home *** CD-ROM | disk | FTP | other *** search
/ Freelog 115 / FreelogNo115-MaiJuin2013.iso / Internet / AvantBrowser / asetup.exe / _data / webkit / resources.pak / Unnamed File 000116.unknown < prev    next >
Text File  |  2013-04-03  |  170KB  |  5,602 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7. WebInspector.JavaScriptBreakpointsSidebarPane = function(breakpointManager, showSourceLineDelegate)
  8. {
  9. WebInspector.SidebarPane.call(this, WebInspector.UIString("Breakpoints"));
  10.  
  11. this._breakpointManager = breakpointManager;
  12. this._showSourceLineDelegate = showSourceLineDelegate;
  13.  
  14. this.listElement = document.createElement("ol");
  15. this.listElement.className = "breakpoint-list";
  16.  
  17. this.emptyElement = document.createElement("div");
  18. this.emptyElement.className = "info";
  19. this.emptyElement.textContent = WebInspector.UIString("No Breakpoints");
  20.  
  21. this.bodyElement.appendChild(this.emptyElement);
  22.  
  23. this._items = new Map();
  24.  
  25. var breakpointLocations = this._breakpointManager.allBreakpointLocations();
  26. for (var i = 0; i < breakpointLocations.length; ++i)
  27. this._addBreakpoint(breakpointLocations[i].breakpoint, breakpointLocations[i].uiLocation);
  28.  
  29. this._breakpointManager.addEventListener(WebInspector.BreakpointManager.Events.BreakpointAdded, this._breakpointAdded, this);
  30. this._breakpointManager.addEventListener(WebInspector.BreakpointManager.Events.BreakpointRemoved, this._breakpointRemoved, this);
  31.  
  32. this.emptyElement.addEventListener("contextmenu", this._emptyElementContextMenu.bind(this), true);
  33. }
  34.  
  35. WebInspector.JavaScriptBreakpointsSidebarPane.prototype = {
  36. _emptyElementContextMenu: function(event)
  37. {
  38. var contextMenu = new WebInspector.ContextMenu(event);
  39. var breakpointActive = WebInspector.debuggerModel.breakpointsActive();
  40. var breakpointActiveTitle = WebInspector.UIString(breakpointActive ? "Deactivate Breakpoints" : "Activate Breakpoints");
  41. contextMenu.appendItem(breakpointActiveTitle, WebInspector.debuggerModel.setBreakpointsActive.bind(WebInspector.debuggerModel, !breakpointActive));
  42. contextMenu.show();
  43. },
  44.  
  45.  
  46. _breakpointAdded: function(event)
  47. {
  48. this._breakpointRemoved(event);
  49.  
  50. var breakpoint =   (event.data.breakpoint);
  51. var uiLocation =   (event.data.uiLocation);
  52. this._addBreakpoint(breakpoint, uiLocation);
  53. },
  54.  
  55.  
  56. _addBreakpoint: function(breakpoint, uiLocation)
  57. {
  58. var element = document.createElement("li");
  59. element.addStyleClass("cursor-pointer");
  60. element.addEventListener("contextmenu", this._breakpointContextMenu.bind(this, breakpoint), true);
  61. element.addEventListener("click", this._breakpointClicked.bind(this, uiLocation), false);
  62.  
  63. var checkbox = document.createElement("input");
  64. checkbox.className = "checkbox-elem";
  65. checkbox.type = "checkbox";
  66. checkbox.checked = breakpoint.enabled();
  67. checkbox.addEventListener("click", this._breakpointCheckboxClicked.bind(this, breakpoint), false);
  68. element.appendChild(checkbox);
  69.  
  70. var labelElement = document.createTextNode(WebInspector.formatLinkText(uiLocation.uiSourceCode.url, uiLocation.lineNumber));
  71. element.appendChild(labelElement);
  72.  
  73. var snippetElement = document.createElement("div");
  74. snippetElement.className = "source-text monospace";
  75. element.appendChild(snippetElement);
  76.  
  77.  
  78. function didRequestContent(content, contentEncoded, mimeType)
  79. {
  80. var lineEndings = content.lineEndings();
  81. if (uiLocation.lineNumber < lineEndings.length)
  82. snippetElement.textContent = content.substring(lineEndings[uiLocation.lineNumber - 1], lineEndings[uiLocation.lineNumber]);
  83. }
  84. uiLocation.uiSourceCode.requestContent(didRequestContent.bind(this));
  85.  
  86. element._data = uiLocation;
  87. var currentElement = this.listElement.firstChild;
  88. while (currentElement) {
  89. if (currentElement._data && this._compareBreakpoints(currentElement._data, element._data) > 0)
  90. break;
  91. currentElement = currentElement.nextSibling;
  92. }
  93. this._addListElement(element, currentElement);
  94.  
  95. var breakpointItem = {};
  96. breakpointItem.element = element;
  97. breakpointItem.checkbox = checkbox;
  98. this._items.put(breakpoint, breakpointItem);
  99.  
  100. if (!this.expanded)
  101. this.expanded = true;
  102. },
  103.  
  104.  
  105. _breakpointRemoved: function(event)
  106. {
  107. var breakpoint =   (event.data.breakpoint);
  108. var uiLocation =   (event.data.uiLocation);
  109. var breakpointItem = this._items.get(breakpoint);
  110. if (!breakpointItem)
  111. return;
  112. this._items.remove(breakpoint);
  113. this._removeListElement(breakpointItem.element);
  114. },
  115.  
  116.  
  117. highlightBreakpoint: function(breakpoint)
  118. {
  119. var breakpointItem = this._items.get(breakpoint);
  120. if (!breakpointItem)
  121. return;
  122. breakpointItem.element.addStyleClass("breakpoint-hit");
  123. this._highlightedBreakpointItem = breakpointItem;
  124. },
  125.  
  126. clearBreakpointHighlight: function()
  127. {
  128. if (this._highlightedBreakpointItem) {
  129. this._highlightedBreakpointItem.element.removeStyleClass("breakpoint-hit");
  130. delete this._highlightedBreakpointItem;
  131. }
  132. },
  133.  
  134. _breakpointClicked: function(uiLocation, event)
  135. {
  136. this._showSourceLineDelegate(uiLocation.uiSourceCode, uiLocation.lineNumber);
  137. },
  138.  
  139.  
  140. _breakpointCheckboxClicked: function(breakpoint, event)
  141. {
  142.  
  143. event.consume();
  144. breakpoint.setEnabled(event.target.checked);
  145. },
  146.  
  147.  
  148. _breakpointContextMenu: function(breakpoint, event)
  149. {
  150. var breakpoints = this._items.values();
  151. var contextMenu = new WebInspector.ContextMenu(event);
  152. contextMenu.appendItem(WebInspector.UIString("Remove Breakpoint"), breakpoint.remove.bind(breakpoint));
  153. if (breakpoints.length > 1) {
  154. var removeAllTitle = WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Remove all breakpoints" : "Remove All Breakpoints");
  155. contextMenu.appendItem(removeAllTitle, this._breakpointManager.removeAllBreakpoints.bind(this._breakpointManager));
  156. }
  157.  
  158. contextMenu.appendSeparator();
  159. var breakpointActive = WebInspector.debuggerModel.breakpointsActive();
  160. var breakpointActiveTitle = WebInspector.UIString(breakpointActive ? "Deactivate Breakpoints" : "Activate Breakpoints");
  161. contextMenu.appendItem(breakpointActiveTitle, WebInspector.debuggerModel.setBreakpointsActive.bind(WebInspector.debuggerModel, !breakpointActive));
  162.  
  163. function enabledBreakpointCount(breakpoints)
  164. {
  165. var count = 0;
  166. for (var i = 0; i < breakpoints.length; ++i) {
  167. if (breakpoints[i].checkbox.checked)
  168. count++;
  169. }
  170. return count;
  171. }
  172. if (breakpoints.length > 1) {
  173. var enableBreakpointCount = enabledBreakpointCount(breakpoints);
  174. var enableTitle = WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Enable all breakpoints" : "Enable All Breakpoints");
  175. var disableTitle = WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Disable all breakpoints" : "Disable All Breakpoints");
  176.  
  177. contextMenu.appendSeparator();
  178.  
  179. contextMenu.appendItem(enableTitle, this._breakpointManager.toggleAllBreakpoints.bind(this._breakpointManager, true), !(enableBreakpointCount != breakpoints.length));
  180. contextMenu.appendItem(disableTitle, this._breakpointManager.toggleAllBreakpoints.bind(this._breakpointManager, false), !(enableBreakpointCount > 1));
  181. }
  182.  
  183. contextMenu.show();
  184. },
  185.  
  186. _addListElement: function(element, beforeElement)
  187. {
  188. if (beforeElement)
  189. this.listElement.insertBefore(element, beforeElement);
  190. else {
  191. if (!this.listElement.firstChild) {
  192. this.bodyElement.removeChild(this.emptyElement);
  193. this.bodyElement.appendChild(this.listElement);
  194. }
  195. this.listElement.appendChild(element);
  196. }
  197. },
  198.  
  199. _removeListElement: function(element)
  200. {
  201. this.listElement.removeChild(element);
  202. if (!this.listElement.firstChild) {
  203. this.bodyElement.removeChild(this.listElement);
  204. this.bodyElement.appendChild(this.emptyElement);
  205. }
  206. },
  207.  
  208. _compare: function(x, y)
  209. {
  210. if (x !== y)
  211. return x < y ? -1 : 1;
  212. return 0;
  213. },
  214.  
  215. _compareBreakpoints: function(b1, b2)
  216. {
  217. return this._compare(b1.url, b2.url) || this._compare(b1.lineNumber, b2.lineNumber);
  218. },
  219.  
  220. reset: function()
  221. {
  222. this.listElement.removeChildren();
  223. if (this.listElement.parentElement) {
  224. this.bodyElement.removeChild(this.listElement);
  225. this.bodyElement.appendChild(this.emptyElement);
  226. }
  227. this._items.clear();
  228. },
  229.  
  230. __proto__: WebInspector.SidebarPane.prototype
  231. }
  232.  
  233.  
  234. WebInspector.XHRBreakpointsSidebarPane = function()
  235. {
  236. WebInspector.NativeBreakpointsSidebarPane.call(this, WebInspector.UIString("XHR Breakpoints"));
  237.  
  238. this._breakpointElements = {};
  239.  
  240. var addButton = document.createElement("button");
  241. addButton.className = "pane-title-button add";
  242. addButton.addEventListener("click", this._addButtonClicked.bind(this), false);
  243. addButton.title = WebInspector.UIString("Add XHR breakpoint");
  244. this.titleElement.appendChild(addButton);
  245.  
  246. this.emptyElement.addEventListener("contextmenu", this._emptyElementContextMenu.bind(this), true);
  247.  
  248. this._restoreBreakpoints();
  249. }
  250.  
  251. WebInspector.XHRBreakpointsSidebarPane.prototype = {
  252. _emptyElementContextMenu: function(event)
  253. {
  254. var contextMenu = new WebInspector.ContextMenu(event);
  255. contextMenu.appendItem(WebInspector.UIString("Add Breakpoint"), this._addButtonClicked.bind(this));
  256. contextMenu.show();
  257. },
  258.  
  259. _addButtonClicked: function(event)
  260. {
  261. if (event)
  262. event.consume();
  263.  
  264. this.expanded = true;
  265.  
  266. var inputElementContainer = document.createElement("p");
  267. inputElementContainer.className = "breakpoint-condition";
  268. var inputElement = document.createElement("span");
  269. inputElementContainer.textContent = WebInspector.UIString("Break when URL contains:");
  270. inputElement.className = "editing";
  271. inputElement.id = "breakpoint-condition-input";
  272. inputElementContainer.appendChild(inputElement);
  273. this._addListElement(inputElementContainer, this.listElement.firstChild);
  274.  
  275. function finishEditing(accept, e, text)
  276. {
  277. this._removeListElement(inputElementContainer);
  278. if (accept) {
  279. this._setBreakpoint(text, true);
  280. this._saveBreakpoints();
  281. }
  282. }
  283.  
  284. var config = new WebInspector.EditingConfig(finishEditing.bind(this, true), finishEditing.bind(this, false));
  285. WebInspector.startEditing(inputElement, config);
  286. },
  287.  
  288. _setBreakpoint: function(url, enabled)
  289. {
  290. if (url in this._breakpointElements)
  291. return;
  292.  
  293. var element = document.createElement("li");
  294. element._url = url;
  295. element.addEventListener("contextmenu", this._contextMenu.bind(this, url), true);
  296.  
  297. var checkboxElement = document.createElement("input");
  298. checkboxElement.className = "checkbox-elem";
  299. checkboxElement.type = "checkbox";
  300. checkboxElement.checked = enabled;
  301. checkboxElement.addEventListener("click", this._checkboxClicked.bind(this, url), false);
  302. element._checkboxElement = checkboxElement;
  303. element.appendChild(checkboxElement);
  304.  
  305. var labelElement = document.createElement("span");
  306. if (!url)
  307. labelElement.textContent = WebInspector.UIString("Any XHR");
  308. else
  309. labelElement.textContent = WebInspector.UIString("URL contains \"%s\"", url);
  310. labelElement.addStyleClass("cursor-auto");
  311. labelElement.addEventListener("dblclick", this._labelClicked.bind(this, url), false);
  312. element.appendChild(labelElement);
  313.  
  314. var currentElement = this.listElement.firstChild;
  315. while (currentElement) {
  316. if (currentElement._url && currentElement._url < element._url)
  317. break;
  318. currentElement = currentElement.nextSibling;
  319. }
  320. this._addListElement(element, currentElement);
  321. this._breakpointElements[url] = element;
  322. if (enabled)
  323. DOMDebuggerAgent.setXHRBreakpoint(url);
  324. },
  325.  
  326. _removeBreakpoint: function(url)
  327. {
  328. var element = this._breakpointElements[url];
  329. if (!element)
  330. return;
  331.  
  332. this._removeListElement(element);
  333. delete this._breakpointElements[url];
  334. if (element._checkboxElement.checked)
  335. DOMDebuggerAgent.removeXHRBreakpoint(url);
  336. },
  337.  
  338. _contextMenu: function(url, event)
  339. {
  340. var contextMenu = new WebInspector.ContextMenu(event);
  341. function removeBreakpoint()
  342. {
  343. this._removeBreakpoint(url);
  344. this._saveBreakpoints();
  345. }
  346. function removeAllBreakpoints()
  347. {
  348. for (var url in this._breakpointElements)
  349. this._removeBreakpoint(url);
  350. this._saveBreakpoints();
  351. }
  352. var removeAllTitle = WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Remove all breakpoints" : "Remove All Breakpoints");
  353.  
  354. contextMenu.appendItem(WebInspector.UIString("Add Breakpoint"), this._addButtonClicked.bind(this));
  355. contextMenu.appendItem(WebInspector.UIString("Remove Breakpoint"), removeBreakpoint.bind(this));
  356. contextMenu.appendItem(removeAllTitle, removeAllBreakpoints.bind(this));
  357. contextMenu.show();
  358. },
  359.  
  360. _checkboxClicked: function(url, event)
  361. {
  362. if (event.target.checked)
  363. DOMDebuggerAgent.setXHRBreakpoint(url);
  364. else
  365. DOMDebuggerAgent.removeXHRBreakpoint(url);
  366. this._saveBreakpoints();
  367. },
  368.  
  369. _labelClicked: function(url)
  370. {
  371. var element = this._breakpointElements[url];
  372. var inputElement = document.createElement("span");
  373. inputElement.className = "breakpoint-condition editing";
  374. inputElement.textContent = url;
  375. this.listElement.insertBefore(inputElement, element);
  376. element.addStyleClass("hidden");
  377.  
  378. function finishEditing(accept, e, text)
  379. {
  380. this._removeListElement(inputElement);
  381. if (accept) {
  382. this._removeBreakpoint(url);
  383. this._setBreakpoint(text, element._checkboxElement.checked);
  384. this._saveBreakpoints();
  385. } else
  386. element.removeStyleClass("hidden");
  387. }
  388.  
  389. WebInspector.startEditing(inputElement, new WebInspector.EditingConfig(finishEditing.bind(this, true), finishEditing.bind(this, false)));
  390. },
  391.  
  392. highlightBreakpoint: function(url)
  393. {
  394. var element = this._breakpointElements[url];
  395. if (!element)
  396. return;
  397. this.expanded = true;
  398. element.addStyleClass("breakpoint-hit");
  399. this._highlightedElement = element;
  400. },
  401.  
  402. clearBreakpointHighlight: function()
  403. {
  404. if (this._highlightedElement) {
  405. this._highlightedElement.removeStyleClass("breakpoint-hit");
  406. delete this._highlightedElement;
  407. }
  408. },
  409.  
  410. _saveBreakpoints: function()
  411. {
  412. var breakpoints = [];
  413. for (var url in this._breakpointElements)
  414. breakpoints.push({ url: url, enabled: this._breakpointElements[url]._checkboxElement.checked });
  415. WebInspector.settings.xhrBreakpoints.set(breakpoints);
  416. },
  417.  
  418. _restoreBreakpoints: function()
  419. {
  420. var breakpoints = WebInspector.settings.xhrBreakpoints.get();
  421. for (var i = 0; i < breakpoints.length; ++i) {
  422. var breakpoint = breakpoints[i];
  423. if (breakpoint && typeof breakpoint.url === "string")
  424. this._setBreakpoint(breakpoint.url, breakpoint.enabled);
  425. }
  426. },
  427.  
  428. __proto__: WebInspector.NativeBreakpointsSidebarPane.prototype
  429. }
  430.  
  431.  
  432. WebInspector.EventListenerBreakpointsSidebarPane = function()
  433. {
  434. WebInspector.SidebarPane.call(this, WebInspector.UIString("Event Listener Breakpoints"));
  435.  
  436. this.categoriesElement = document.createElement("ol");
  437. this.categoriesElement.tabIndex = 0;
  438. this.categoriesElement.addStyleClass("properties-tree");
  439. this.categoriesElement.addStyleClass("event-listener-breakpoints");
  440. this.categoriesTreeOutline = new TreeOutline(this.categoriesElement);
  441. this.bodyElement.appendChild(this.categoriesElement);
  442.  
  443. this._breakpointItems = {};
  444.  
  445.  
  446.  
  447. this._createCategory(WebInspector.UIString("Animation"), false, ["requestAnimationFrame", "cancelAnimationFrame", "animationFrameFired"]);
  448. this._createCategory(WebInspector.UIString("Control"), true, ["resize", "scroll", "zoom", "focus", "blur", "select", "change", "submit", "reset"]);
  449. this._createCategory(WebInspector.UIString("Clipboard"), true, ["copy", "cut", "paste", "beforecopy", "beforecut", "beforepaste"]);
  450. this._createCategory(WebInspector.UIString("DOM Mutation"), true, ["DOMActivate", "DOMFocusIn", "DOMFocusOut", "DOMAttrModified", "DOMCharacterDataModified", "DOMNodeInserted", "DOMNodeInsertedIntoDocument", "DOMNodeRemoved", "DOMNodeRemovedFromDocument", "DOMSubtreeModified", "DOMContentLoaded"]);
  451. this._createCategory(WebInspector.UIString("Device"), true, ["deviceorientation", "devicemotion"]);
  452. this._createCategory(WebInspector.UIString("Keyboard"), true, ["keydown", "keyup", "keypress", "input"]);
  453. this._createCategory(WebInspector.UIString("Load"), true, ["load", "unload", "abort", "error"]);
  454. this._createCategory(WebInspector.UIString("Mouse"), true, ["click", "dblclick", "mousedown", "mouseup", "mouseover", "mousemove", "mouseout", "mousewheel"]);
  455. this._createCategory(WebInspector.UIString("Timer"), false, ["setTimer", "clearTimer", "timerFired"]);
  456. this._createCategory(WebInspector.UIString("Touch"), true, ["touchstart", "touchmove", "touchend", "touchcancel"]);
  457.  
  458. this._restoreBreakpoints();
  459. }
  460.  
  461. WebInspector.EventListenerBreakpointsSidebarPane.categotyListener = "listener:";
  462. WebInspector.EventListenerBreakpointsSidebarPane.categotyInstrumentation = "instrumentation:";
  463.  
  464. WebInspector.EventListenerBreakpointsSidebarPane.eventNameForUI = function(eventName)
  465. {
  466. if (!WebInspector.EventListenerBreakpointsSidebarPane._eventNamesForUI) {
  467. WebInspector.EventListenerBreakpointsSidebarPane._eventNamesForUI = {
  468. "instrumentation:setTimer": WebInspector.UIString("Set Timer"),
  469. "instrumentation:clearTimer": WebInspector.UIString("Clear Timer"),
  470. "instrumentation:timerFired": WebInspector.UIString("Timer Fired"),
  471. "instrumentation:requestAnimationFrame": WebInspector.UIString("Request Animation Frame"),
  472. "instrumentation:cancelAnimationFrame": WebInspector.UIString("Cancel Animation Frame"),
  473. "instrumentation:animationFrameFired": WebInspector.UIString("Animation Frame Fired")
  474. };
  475. }
  476. return WebInspector.EventListenerBreakpointsSidebarPane._eventNamesForUI[eventName] || eventName.substring(eventName.indexOf(":") + 1);
  477. }
  478.  
  479. WebInspector.EventListenerBreakpointsSidebarPane.prototype = {
  480. _createCategory: function(name, isDOMEvent, eventNames)
  481. {
  482. var categoryItem = {};
  483. categoryItem.element = new TreeElement(name);
  484. this.categoriesTreeOutline.appendChild(categoryItem.element);
  485. categoryItem.element.listItemElement.addStyleClass("event-category");
  486. categoryItem.element.selectable = true;
  487.  
  488. categoryItem.checkbox = this._createCheckbox(categoryItem.element);
  489. categoryItem.checkbox.addEventListener("click", this._categoryCheckboxClicked.bind(this, categoryItem), true);
  490.  
  491. categoryItem.children = {};
  492. for (var i = 0; i < eventNames.length; ++i) {
  493. var eventName = (isDOMEvent ? WebInspector.EventListenerBreakpointsSidebarPane.categotyListener :  WebInspector.EventListenerBreakpointsSidebarPane.categotyInstrumentation) + eventNames[i];
  494.  
  495. var breakpointItem = {};
  496. var title = WebInspector.EventListenerBreakpointsSidebarPane.eventNameForUI(eventName);
  497. breakpointItem.element = new TreeElement(title);
  498. categoryItem.element.appendChild(breakpointItem.element);
  499. var hitMarker = document.createElement("div");
  500. hitMarker.className = "breakpoint-hit-marker";
  501. breakpointItem.element.listItemElement.appendChild(hitMarker);
  502. breakpointItem.element.listItemElement.addStyleClass("source-code");
  503. breakpointItem.element.selectable = true;
  504.  
  505. breakpointItem.checkbox = this._createCheckbox(breakpointItem.element);
  506. breakpointItem.checkbox.addEventListener("click", this._breakpointCheckboxClicked.bind(this, eventName), true);
  507. breakpointItem.parent = categoryItem;
  508.  
  509. this._breakpointItems[eventName] = breakpointItem;
  510. categoryItem.children[eventName] = breakpointItem;
  511. }
  512. },
  513.  
  514. _createCheckbox: function(treeElement)
  515. {
  516. var checkbox = document.createElement("input");
  517. checkbox.className = "checkbox-elem";
  518. checkbox.type = "checkbox";
  519. treeElement.listItemElement.insertBefore(checkbox, treeElement.listItemElement.firstChild);
  520. return checkbox;
  521. },
  522.  
  523. _categoryCheckboxClicked: function(categoryItem)
  524. {
  525. var checked = categoryItem.checkbox.checked;
  526. for (var eventName in categoryItem.children) {
  527. var breakpointItem = categoryItem.children[eventName];
  528. if (breakpointItem.checkbox.checked === checked)
  529. continue;
  530. if (checked)
  531. this._setBreakpoint(eventName);
  532. else
  533. this._removeBreakpoint(eventName);
  534. }
  535. this._saveBreakpoints();
  536. },
  537.  
  538. _breakpointCheckboxClicked: function(eventName, event)
  539. {
  540. if (event.target.checked)
  541. this._setBreakpoint(eventName);
  542. else
  543. this._removeBreakpoint(eventName);
  544. this._saveBreakpoints();
  545. },
  546.  
  547. _setBreakpoint: function(eventName)
  548. {
  549. var breakpointItem = this._breakpointItems[eventName];
  550. if (!breakpointItem)
  551. return;
  552. breakpointItem.checkbox.checked = true;
  553. if (eventName.startsWith(WebInspector.EventListenerBreakpointsSidebarPane.categotyListener))
  554. DOMDebuggerAgent.setEventListenerBreakpoint(eventName.substring(WebInspector.EventListenerBreakpointsSidebarPane.categotyListener.length));
  555. else if (eventName.startsWith(WebInspector.EventListenerBreakpointsSidebarPane.categotyInstrumentation))
  556. DOMDebuggerAgent.setInstrumentationBreakpoint(eventName.substring(WebInspector.EventListenerBreakpointsSidebarPane.categotyInstrumentation.length));
  557. this._updateCategoryCheckbox(breakpointItem.parent);
  558. },
  559.  
  560. _removeBreakpoint: function(eventName)
  561. {
  562. var breakpointItem = this._breakpointItems[eventName];
  563. if (!breakpointItem)
  564. return;
  565. breakpointItem.checkbox.checked = false;
  566. if (eventName.startsWith(WebInspector.EventListenerBreakpointsSidebarPane.categotyListener))
  567. DOMDebuggerAgent.removeEventListenerBreakpoint(eventName.substring(WebInspector.EventListenerBreakpointsSidebarPane.categotyListener.length));
  568. else if (eventName.startsWith(WebInspector.EventListenerBreakpointsSidebarPane.categotyInstrumentation))
  569. DOMDebuggerAgent.removeInstrumentationBreakpoint(eventName.substring(WebInspector.EventListenerBreakpointsSidebarPane.categotyInstrumentation.length));
  570. this._updateCategoryCheckbox(breakpointItem.parent);
  571. },
  572.  
  573. _updateCategoryCheckbox: function(categoryItem)
  574. {
  575. var hasEnabled = false, hasDisabled = false;
  576. for (var eventName in categoryItem.children) {
  577. var breakpointItem = categoryItem.children[eventName];
  578. if (breakpointItem.checkbox.checked)
  579. hasEnabled = true;
  580. else
  581. hasDisabled = true;
  582. }
  583. categoryItem.checkbox.checked = hasEnabled;
  584. categoryItem.checkbox.indeterminate = hasEnabled && hasDisabled;
  585. },
  586.  
  587. highlightBreakpoint: function(eventName)
  588. {
  589. var breakpointItem = this._breakpointItems[eventName];
  590. if (!breakpointItem)
  591. return;
  592. this.expanded = true;
  593. breakpointItem.parent.element.expand();
  594. breakpointItem.element.listItemElement.addStyleClass("breakpoint-hit");
  595. this._highlightedElement = breakpointItem.element.listItemElement;
  596. },
  597.  
  598. clearBreakpointHighlight: function()
  599. {
  600. if (this._highlightedElement) {
  601. this._highlightedElement.removeStyleClass("breakpoint-hit");
  602. delete this._highlightedElement;
  603. }
  604. },
  605.  
  606. _saveBreakpoints: function()
  607. {
  608. var breakpoints = [];
  609. for (var eventName in this._breakpointItems) {
  610. if (this._breakpointItems[eventName].checkbox.checked)
  611. breakpoints.push({ eventName: eventName });
  612. }
  613. WebInspector.settings.eventListenerBreakpoints.set(breakpoints);
  614. },
  615.  
  616. _restoreBreakpoints: function()
  617. {
  618. var breakpoints = WebInspector.settings.eventListenerBreakpoints.get();
  619. for (var i = 0; i < breakpoints.length; ++i) {
  620. var breakpoint = breakpoints[i];
  621. if (breakpoint && typeof breakpoint.eventName === "string")
  622. this._setBreakpoint(breakpoint.eventName);
  623. }
  624. },
  625.  
  626. __proto__: WebInspector.SidebarPane.prototype
  627. }
  628. ;
  629.  
  630.  
  631.  
  632. WebInspector.CallStackSidebarPane = function()
  633. {
  634. WebInspector.SidebarPane.call(this, WebInspector.UIString("Call Stack"));
  635. this._model = WebInspector.debuggerModel;
  636.  
  637. this.bodyElement.addEventListener("keydown", this._keyDown.bind(this), true);
  638. this.bodyElement.tabIndex = 0;
  639. }
  640.  
  641. WebInspector.CallStackSidebarPane.prototype = {
  642. update: function(callFrames)
  643. {
  644. this.bodyElement.removeChildren();
  645. delete this._statusMessageElement;
  646. this.placards = [];
  647.  
  648. if (!callFrames) {
  649. var infoElement = document.createElement("div");
  650. infoElement.className = "info";
  651. infoElement.textContent = WebInspector.UIString("Not Paused");
  652. this.bodyElement.appendChild(infoElement);
  653. return;
  654. }
  655.  
  656. for (var i = 0; i < callFrames.length; ++i) {
  657. var callFrame = callFrames[i];
  658. var placard = new WebInspector.CallStackSidebarPane.Placard(callFrame, this);
  659. placard.element.addEventListener("click", this._placardSelected.bind(this, placard), false);
  660. this.placards.push(placard);
  661. this.bodyElement.appendChild(placard.element);
  662. }
  663. },
  664.  
  665. setSelectedCallFrame: function(x)
  666. {
  667. for (var i = 0; i < this.placards.length; ++i) {
  668. var placard = this.placards[i];
  669. placard.selected = (placard._callFrame === x);
  670. }
  671. },
  672.  
  673. _selectNextCallFrameOnStack: function()
  674. {
  675. var index = this._selectedCallFrameIndex();
  676. if (index == -1)
  677. return;
  678. this._selectedPlacardByIndex(index + 1);
  679. },
  680.  
  681. _selectPreviousCallFrameOnStack: function()
  682. {
  683. var index = this._selectedCallFrameIndex();
  684. if (index == -1)
  685. return;
  686. this._selectedPlacardByIndex(index - 1);
  687. },
  688.  
  689. _selectedPlacardByIndex: function(index)
  690. {
  691. if (index < 0 || index >= this.placards.length)
  692. return;
  693. this._placardSelected(this.placards[index])
  694. },
  695.  
  696. _selectedCallFrameIndex: function()
  697. {
  698. if (!this._model.selectedCallFrame())
  699. return -1;
  700. for (var i = 0; i < this.placards.length; ++i) {
  701. var placard = this.placards[i];
  702. if (placard._callFrame === this._model.selectedCallFrame())
  703. return i;
  704. }
  705. return -1;
  706. },
  707.  
  708. _placardSelected: function(placard)
  709. {
  710. this._model.setSelectedCallFrame(placard._callFrame);
  711. },
  712.  
  713. _copyStackTrace: function()
  714. {
  715. var text = "";
  716. for (var i = 0; i < this.placards.length; ++i)
  717. text += this.placards[i].title + " (" + this.placards[i].subtitle + ")\n";
  718. InspectorFrontendHost.copyText(text);
  719. },
  720.  
  721.  
  722. registerShortcuts: function(registerShortcutDelegate)
  723. {
  724. registerShortcutDelegate(WebInspector.ScriptsPanelDescriptor.ShortcutKeys.NextCallFrame, this._selectNextCallFrameOnStack.bind(this));
  725. registerShortcutDelegate(WebInspector.ScriptsPanelDescriptor.ShortcutKeys.PrevCallFrame, this._selectPreviousCallFrameOnStack.bind(this));
  726. },
  727.  
  728. setStatus: function(status)
  729. {
  730. if (!this._statusMessageElement) {
  731. this._statusMessageElement = document.createElement("div");
  732. this._statusMessageElement.className = "info";
  733. this.bodyElement.appendChild(this._statusMessageElement);
  734. }
  735. if (typeof status === "string")
  736. this._statusMessageElement.textContent = status;
  737. else {
  738. this._statusMessageElement.removeChildren();
  739. this._statusMessageElement.appendChild(status);
  740. }
  741. },
  742.  
  743. _keyDown: function(event)
  744. {
  745. if (event.altKey || event.shiftKey || event.metaKey || event.ctrlKey)
  746. return;
  747.  
  748. if (event.keyIdentifier === "Up") {
  749. this._selectPreviousCallFrameOnStack();
  750. event.consume();
  751. } else if (event.keyIdentifier === "Down") {
  752. this._selectNextCallFrameOnStack();
  753. event.consume();
  754. }
  755. },
  756.  
  757. __proto__: WebInspector.SidebarPane.prototype
  758. }
  759.  
  760.  
  761. WebInspector.CallStackSidebarPane.Placard = function(callFrame, pane)
  762. {
  763. WebInspector.Placard.call(this, callFrame.functionName || WebInspector.UIString("(anonymous function)"), "");
  764. callFrame.createLiveLocation(this._update.bind(this));
  765. this.element.addEventListener("contextmenu", this._placardContextMenu.bind(this), true);
  766. this._callFrame = callFrame;
  767. this._pane = pane;
  768. }
  769.  
  770. WebInspector.CallStackSidebarPane.Placard.prototype = {
  771. _update: function(uiLocation)
  772. {
  773. this.subtitle = WebInspector.formatLinkText(uiLocation.uiSourceCode.url, uiLocation.lineNumber).trimMiddle(100);
  774. },
  775.  
  776. _placardContextMenu: function(event)
  777. {
  778. var contextMenu = new WebInspector.ContextMenu(event);
  779.  
  780. if (WebInspector.debuggerModel.canSetScriptSource()) {
  781. contextMenu.appendItem(WebInspector.UIString("Restart Frame"), this._restartFrame.bind(this));
  782. contextMenu.appendSeparator();
  783. }
  784. contextMenu.appendItem(WebInspector.UIString("Copy Stack Trace"), this._pane._copyStackTrace.bind(this._pane));
  785.  
  786. contextMenu.show();
  787. },
  788.  
  789. _restartFrame: function()
  790. {
  791. this._callFrame.restart(undefined);
  792. },
  793.  
  794. __proto__: WebInspector.Placard.prototype
  795. }
  796. ;
  797.  
  798.  
  799.  
  800. WebInspector.FilteredItemSelectionDialog = function(delegate)
  801. {
  802. WebInspector.DialogDelegate.call(this);
  803.  
  804. var xhr = new XMLHttpRequest();
  805. xhr.open("GET", "filteredItemSelectionDialog.css", false);
  806. xhr.send(null);
  807.  
  808. this.element = document.createElement("div");
  809. this.element.className = "js-outline-dialog";
  810. this.element.addEventListener("keydown", this._onKeyDown.bind(this), false);
  811. this.element.addEventListener("mousemove", this._onMouseMove.bind(this), false);
  812. this.element.addEventListener("click", this._onClick.bind(this), false);
  813. var styleElement = this.element.createChild("style");
  814. styleElement.type = "text/css";
  815. styleElement.textContent = xhr.responseText;
  816.  
  817. this._itemElements = [];
  818. this._elementIndexes = new Map();
  819. this._elementHighlightChanges = new Map();
  820.  
  821. this._promptElement = this.element.createChild("input", "monospace");
  822. this._promptElement.type = "text";
  823. this._promptElement.setAttribute("spellcheck", "false");
  824.  
  825. this._progressElement = this.element.createChild("div", "progress");
  826.  
  827. this._itemElementsContainer = document.createElement("div");
  828. this._itemElementsContainer.className = "container monospace";
  829. this._itemElementsContainer.addEventListener("scroll", this._onScroll.bind(this), false);
  830. this.element.appendChild(this._itemElementsContainer);
  831.  
  832. this._delegate = delegate;
  833.  
  834. this._delegate.requestItems(this._itemsLoaded.bind(this));
  835. }
  836.  
  837. WebInspector.FilteredItemSelectionDialog.prototype = {
  838.  
  839. position: function(element, relativeToElement)
  840. {
  841. const minWidth = 500;
  842. const minHeight = 204;
  843. var width = Math.max(relativeToElement.offsetWidth * 2 / 3, minWidth);
  844. var height = Math.max(relativeToElement.offsetHeight * 2 / 3, minHeight);
  845.  
  846. this.element.style.width = width + "px";
  847. this.element.style.height = height + "px";
  848.  
  849. const shadowPadding = 20; 
  850. element.positionAt(
  851. relativeToElement.totalOffsetLeft() + Math.max((relativeToElement.offsetWidth - width - 2 * shadowPadding) / 2, shadowPadding),
  852. relativeToElement.totalOffsetTop() + Math.max((relativeToElement.offsetHeight - height - 2 * shadowPadding) / 2, shadowPadding));
  853. },
  854.  
  855. focus: function()
  856. {
  857. WebInspector.setCurrentFocusElement(this._promptElement);
  858. },
  859.  
  860. willHide: function()
  861. {
  862. if (this._isHiding)
  863. return;
  864. this._isHiding = true;
  865. if (this._filterTimer)
  866. clearTimeout(this._filterTimer);
  867. },
  868.  
  869. onEnter: function()
  870. {
  871. if (!this._selectedElement)
  872. return;
  873. this._delegate.selectItem(this._elementIndexes.get(this._selectedElement), this._promptElement.value.trim());
  874. },
  875.  
  876.  
  877. _itemsLoaded: function(index, chunkLength, chunkIndex, chunkCount)
  878. {
  879. for (var i = index; i < index + chunkLength; ++i)
  880. this._itemElementsContainer.appendChild(this._createItemElement(i));
  881. this._filterItems();
  882.  
  883. if (chunkIndex === chunkCount)
  884. this._progressElement.style.backgroundImage = "";
  885. else {
  886. const color = "rgb(66, 129, 235)";
  887. const percent = ((chunkIndex / chunkCount) * 100) + "%";
  888. this._progressElement.style.backgroundImage = "-webkit-linear-gradient(left, " + color + ", " + color + " " + percent + ",  transparent " + percent + ")";
  889. }
  890. },
  891.  
  892.  
  893. _createItemElement: function(index)
  894. {
  895. if (this._itemElements[index])
  896. return this._itemElements[index];
  897.  
  898. var itemElement = document.createElement("div");
  899. itemElement.className = "item";
  900. itemElement._titleElement = itemElement.createChild("span");
  901. itemElement._titleElement.textContent = this._delegate.itemTitleAt(index);
  902. itemElement._titleSuffixElement = itemElement.createChild("span");
  903. itemElement._subtitleElement = itemElement.createChild("span", "subtitle");
  904. itemElement._subtitleElement.textContent = this._delegate.itemSubtitleAt(index);
  905. this._elementIndexes.put(itemElement, index);
  906. this._itemElements.push(itemElement);
  907. return itemElement;
  908. },
  909.  
  910.  
  911. _hideItemElement: function(itemElement)
  912. {
  913. itemElement.style.display = "none";
  914. },
  915.  
  916.  
  917. _itemElementVisible: function(itemElement)
  918. {
  919. return itemElement.style.display !== "none";
  920. },
  921.  
  922.  
  923. _showItemElement: function(itemElement)
  924. {
  925. itemElement.style.display = "";
  926. },
  927.  
  928.  
  929. _createSearchRegExp: function(query, isGlobal)
  930. {
  931. return this._innerCreateSearchRegExp(this._delegate.rewriteQuery(query), isGlobal);
  932. },
  933.  
  934.  
  935. _innerCreateSearchRegExp: function(query, isGlobal)
  936. {
  937. if (!query)
  938. return new RegExp(".*");
  939. query = query.trim();
  940.  
  941. var ignoreCase = (query === query.toLowerCase());
  942. var regExpString = query.escapeForRegExp().replace(/\\\*/g, ".*").replace(/\\\?/g, ".")
  943. if (ignoreCase)
  944. regExpString = regExpString.replace(/(?!^)(\\\.|[_:-])/g, "[^._:-]*$1");
  945. else
  946. regExpString = regExpString.replace(/(?!^)(\\\.|[A-Z_:-])/g, "[^.A-Z_:-]*$1");
  947. regExpString = regExpString;
  948. return new RegExp(regExpString, (ignoreCase ? "i" : "") + (isGlobal ? "g" : ""));
  949. },
  950.  
  951. _filterItems: function()
  952. {
  953. delete this._filterTimer;
  954.  
  955. var query = this._promptElement.value;
  956. query = query.trim();
  957. var regex = this._createSearchRegExp(query);
  958.  
  959. var firstElement;
  960. for (var i = 0; i < this._itemElements.length; ++i) {
  961. var itemElement = this._itemElements[i];
  962. itemElement._titleSuffixElement.textContent = this._delegate.itemSuffixAt(i);
  963. if (regex.test(this._delegate.itemKeyAt(i))) {
  964. this._showItemElement(itemElement);
  965. if (!firstElement)
  966. firstElement = itemElement;
  967. } else
  968. this._hideItemElement(itemElement);
  969. }
  970.  
  971. if (!this._selectedElement || !this._itemElementVisible(this._selectedElement))
  972. this._updateSelection(firstElement);
  973.  
  974. if (query) {
  975. this._highlightItems(query);
  976. this._query = query;
  977. } else {
  978. this._clearHighlight();
  979. delete this._query;
  980. }
  981. },
  982.  
  983. _onKeyDown: function(event)
  984. {
  985. function nextItem(itemElement, isPageScroll, forward)
  986. {
  987. var scrollItemsLeft = isPageScroll && this._rowsPerViewport ? this._rowsPerViewport : 1;
  988. var candidate = itemElement;
  989. var lastVisibleCandidate = candidate;
  990. do {
  991. candidate = forward ? candidate.nextSibling : candidate.previousSibling;
  992. if (!candidate) {
  993. if (isPageScroll)
  994. return lastVisibleCandidate;
  995. else
  996. candidate = forward ? this._itemElementsContainer.firstChild : this._itemElementsContainer.lastChild;
  997. }
  998. if (!this._itemElementVisible(candidate))
  999. continue;
  1000. lastVisibleCandidate = candidate;
  1001. --scrollItemsLeft;
  1002. } while (scrollItemsLeft && candidate !== this._selectedElement);
  1003.  
  1004. return candidate;
  1005. }
  1006.  
  1007. if (this._selectedElement) {
  1008. var candidate;
  1009. switch (event.keyCode) {
  1010. case WebInspector.KeyboardShortcut.Keys.Down.code:
  1011. candidate = nextItem.call(this, this._selectedElement, false, true);
  1012. break;
  1013. case WebInspector.KeyboardShortcut.Keys.Up.code:
  1014. candidate = nextItem.call(this, this._selectedElement, false, false);
  1015. break;
  1016. case WebInspector.KeyboardShortcut.Keys.PageDown.code:
  1017. candidate = nextItem.call(this, this._selectedElement, true, true);
  1018. break;
  1019. case WebInspector.KeyboardShortcut.Keys.PageUp.code:
  1020. candidate = nextItem.call(this, this._selectedElement, true, false);
  1021. break;
  1022. }
  1023.  
  1024. if (candidate) {
  1025. this._updateSelection(candidate);
  1026. event.preventDefault();
  1027. return;
  1028. }
  1029. }
  1030.  
  1031. if (event.keyIdentifier !== "Shift" && event.keyIdentifier !== "Ctrl" && event.keyIdentifier !== "Meta" && event.keyIdentifier !== "Left" && event.keyIdentifier !== "Right")
  1032. this._scheduleFilter();
  1033. },
  1034.  
  1035. _scheduleFilter: function()
  1036. {
  1037. if (this._filterTimer)
  1038. return;
  1039. this._filterTimer = setTimeout(this._filterItems.bind(this), 0);
  1040. },
  1041.  
  1042.  
  1043. _updateSelection: function(newSelectedElement)
  1044. {
  1045. if (this._selectedElement === newSelectedElement)
  1046. return;
  1047. if (this._selectedElement)
  1048. this._selectedElement.removeStyleClass("selected");
  1049.  
  1050. this._selectedElement = newSelectedElement;
  1051. if (newSelectedElement) {
  1052. newSelectedElement.addStyleClass("selected");
  1053. newSelectedElement.scrollIntoViewIfNeeded(false);
  1054. if (!this._itemHeight) {
  1055. this._itemHeight = newSelectedElement.offsetHeight;
  1056. this._rowsPerViewport = Math.floor(this._itemElementsContainer.offsetHeight / this._itemHeight);
  1057. }
  1058. }
  1059. },
  1060.  
  1061. _onClick: function(event)
  1062. {
  1063. var itemElement = event.target.enclosingNodeOrSelfWithClass("item");
  1064. if (!itemElement)
  1065. return;
  1066. this._updateSelection(itemElement);
  1067. this._delegate.selectItem(this._elementIndexes.get(this._selectedElement), this._promptElement.value.trim());
  1068. WebInspector.Dialog.hide();
  1069. },
  1070.  
  1071. _onMouseMove: function(event)
  1072. {
  1073. var itemElement = event.target.enclosingNodeOrSelfWithClass("item");
  1074. if (!itemElement)
  1075. return;
  1076. this._updateSelection(itemElement);
  1077. },
  1078.  
  1079. _onScroll: function()
  1080. {
  1081. if (this._query)
  1082. this._highlightItems(this._query);
  1083. else
  1084. this._clearHighlight();
  1085. },
  1086.  
  1087.  
  1088. _highlightItems: function(query)
  1089. {
  1090. var regex = this._createSearchRegExp(query, true);
  1091. for (var i = 0; i < this._delegate.itemsCount(); ++i) {
  1092. var itemElement = this._itemElements[i];
  1093. if (this._itemElementVisible(itemElement) && this._itemElementInViewport(itemElement))
  1094. this._highlightItem(itemElement, regex);
  1095. }
  1096. },
  1097.  
  1098. _clearHighlight: function()
  1099. {
  1100. for (var i = 0; i < this._delegate.itemsCount(); ++i)
  1101. this._clearElementHighlight(this._itemElements[i]);
  1102. },
  1103.  
  1104.  
  1105. _clearElementHighlight: function(itemElement)
  1106. {
  1107. var changes = this._elementHighlightChanges.get(itemElement)
  1108. if (changes) {
  1109. WebInspector.revertDomChanges(changes);
  1110. this._elementHighlightChanges.remove(itemElement);
  1111. }
  1112. },
  1113.  
  1114.  
  1115. _highlightItem: function(itemElement, regex)
  1116. {
  1117. this._clearElementHighlight(itemElement);
  1118.  
  1119. var key = this._delegate.itemKeyAt(this._elementIndexes.get(itemElement));
  1120. var ranges = [];
  1121.  
  1122. var match;
  1123. while ((match = regex.exec(key)) !== null && match[0]) {
  1124. ranges.push({ offset: match.index, length: regex.lastIndex - match.index });
  1125. }
  1126.  
  1127. var changes = [];
  1128. WebInspector.highlightRangesWithStyleClass(itemElement, ranges, "highlight", changes);
  1129.  
  1130. if (changes.length)
  1131. this._elementHighlightChanges.put(itemElement, changes);
  1132. },
  1133.  
  1134.  
  1135. _itemElementInViewport: function(itemElement)
  1136. {
  1137. if (itemElement.offsetTop + this._itemHeight < this._itemElementsContainer.scrollTop)
  1138. return false;
  1139. if (itemElement.offsetTop > this._itemElementsContainer.scrollTop + this._itemHeight * (this._rowsPerViewport + 1))
  1140. return false;
  1141. return true;
  1142. },
  1143.  
  1144. __proto__: WebInspector.DialogDelegate.prototype
  1145. }
  1146.  
  1147.  
  1148. WebInspector.SelectionDialogContentProvider = function()
  1149. {
  1150. }
  1151.  
  1152. WebInspector.SelectionDialogContentProvider.prototype = {
  1153.  
  1154. itemTitleAt: function(itemIndex) { },
  1155.  
  1156.  
  1157. itemSuffixAt: function(itemIndex) { },
  1158.  
  1159.  
  1160. itemSubtitleAt: function(itemIndex) { },
  1161.  
  1162.  
  1163. itemKeyAt: function(itemIndex) { },
  1164.  
  1165.  
  1166. itemsCount: function() { },
  1167.  
  1168.  
  1169. requestItems: function(callback) { },
  1170.  
  1171.  
  1172. selectItem: function(itemIndex, promptValue) { },
  1173.  
  1174.  
  1175. rewriteQuery: function(query) { },
  1176. }
  1177.  
  1178.  
  1179. WebInspector.JavaScriptOutlineDialog = function(view, contentProvider)
  1180. {
  1181. WebInspector.SelectionDialogContentProvider.call(this);
  1182.  
  1183. this._functionItems = [];
  1184. this._view = view;
  1185. this._contentProvider = contentProvider;
  1186. }
  1187.  
  1188.  
  1189. WebInspector.JavaScriptOutlineDialog.show = function(view, contentProvider)
  1190. {
  1191. if (WebInspector.Dialog.currentInstance())
  1192. return null;
  1193. var delegate = new WebInspector.JavaScriptOutlineDialog(view, contentProvider);
  1194. var filteredItemSelectionDialog = new WebInspector.FilteredItemSelectionDialog(delegate);
  1195. WebInspector.Dialog.show(view.element, filteredItemSelectionDialog);
  1196. }
  1197.  
  1198. WebInspector.JavaScriptOutlineDialog.prototype = {
  1199.  
  1200. itemTitleAt: function(itemIndex)
  1201. {
  1202. var functionItem = this._functionItems[itemIndex];
  1203. return functionItem.name + (functionItem.arguments ? functionItem.arguments : "");
  1204. },
  1205.  
  1206.  
  1207. itemSuffixAt: function(itemIndex)
  1208. {
  1209. return "";
  1210. },
  1211.  
  1212.  
  1213. itemSubtitleAt: function(itemIndex)
  1214. {
  1215. return ":" + (this._functionItems[itemIndex].line + 1);
  1216. },
  1217.  
  1218.  
  1219. itemKeyAt: function(itemIndex)
  1220. {
  1221. return this._functionItems[itemIndex].name;
  1222. },
  1223.  
  1224.  
  1225. itemsCount: function()
  1226. {
  1227. return this._functionItems.length;
  1228. },
  1229.  
  1230.  
  1231. requestItems: function(callback)
  1232. {
  1233.  
  1234. function contentCallback(content, contentEncoded, mimeType)
  1235. {
  1236. if (this._outlineWorker)
  1237. this._outlineWorker.terminate();
  1238. this._outlineWorker = new Worker("ScriptFormatterWorker.js");
  1239. this._outlineWorker.onmessage = this._didBuildOutlineChunk.bind(this, callback);
  1240. const method = "outline";
  1241. this._outlineWorker.postMessage({ method: method, params: { content: content } });
  1242. }
  1243. this._contentProvider.requestContent(contentCallback.bind(this));
  1244. },
  1245.  
  1246. _didBuildOutlineChunk: function(callback, event)
  1247. {
  1248. var data = event.data;
  1249.  
  1250. var index = this._functionItems.length;
  1251. var chunk = data["chunk"];
  1252. for (var i = 0; i < chunk.length; ++i)
  1253. this._functionItems.push(chunk[i]);
  1254. callback(index, chunk.length, data.index, data.total);
  1255.  
  1256. if (data.total === data.index && this._outlineWorker) {
  1257. this._outlineWorker.terminate();
  1258. delete this._outlineWorker;
  1259. }
  1260. },
  1261.  
  1262.  
  1263. selectItem: function(itemIndex, promptValue)
  1264. {
  1265. var lineNumber = this._functionItems[itemIndex].line;
  1266. if (!isNaN(lineNumber) && lineNumber >= 0)
  1267. this._view.highlightLine(lineNumber);
  1268. this._view.focus();
  1269. },
  1270.  
  1271.  
  1272. rewriteQuery: function(query)
  1273. {
  1274. return query;
  1275. },
  1276.  
  1277. __proto__: WebInspector.SelectionDialogContentProvider.prototype
  1278. }
  1279.  
  1280.  
  1281. WebInspector.OpenResourceDialog = function(panel, uiSourceCodeProvider)
  1282. {
  1283. WebInspector.SelectionDialogContentProvider.call(this);
  1284. this._panel = panel;
  1285.  
  1286. this._uiSourceCodes = uiSourceCodeProvider.uiSourceCodes();
  1287.  
  1288. function filterOutEmptyURLs(uiSourceCode)
  1289. {
  1290. return !!uiSourceCode.parsedURL.lastPathComponent;
  1291. }
  1292. this._uiSourceCodes = this._uiSourceCodes.filter(filterOutEmptyURLs);
  1293.  
  1294. function compareFunction(uiSourceCode1, uiSourceCode2)
  1295. {
  1296. return uiSourceCode1.parsedURL.lastPathComponent.localeCompare(uiSourceCode2.parsedURL.lastPathComponent);
  1297. }
  1298. this._uiSourceCodes.sort(compareFunction);
  1299. }
  1300.  
  1301. WebInspector.OpenResourceDialog.prototype = {
  1302.  
  1303. itemTitleAt: function(itemIndex)
  1304. {
  1305. return this._uiSourceCodes[itemIndex].parsedURL.lastPathComponent;
  1306. },
  1307.  
  1308.  
  1309. itemSuffixAt: function(itemIndex)
  1310. {
  1311. return this._queryLineNumber || "";
  1312. },
  1313.  
  1314.  
  1315. itemSubtitleAt: function(itemIndex)
  1316. {
  1317. return this._uiSourceCodes[itemIndex].parsedURL.folderPathComponents;
  1318. },
  1319.  
  1320.  
  1321. itemKeyAt: function(itemIndex)
  1322. {
  1323. return this._uiSourceCodes[itemIndex].parsedURL.lastPathComponent;
  1324. },
  1325.  
  1326.  
  1327. itemsCount: function()
  1328. {
  1329. return this._uiSourceCodes.length;
  1330. },
  1331.  
  1332.  
  1333. requestItems: function(callback)
  1334. {
  1335. callback(0, this._uiSourceCodes.length, 1, 1);
  1336. },
  1337.  
  1338.  
  1339. selectItem: function(itemIndex, promptValue)
  1340. {
  1341. var lineNumberMatch = promptValue.match(/[^:]+\:([\d]*)$/);
  1342. var lineNumber = lineNumberMatch ? Math.max(parseInt(lineNumberMatch[1], 10) - 1, 0) : 0;
  1343. this._panel.showUISourceCode(this._uiSourceCodes[itemIndex], lineNumber);
  1344. },
  1345.  
  1346.  
  1347. rewriteQuery: function(query)
  1348. {
  1349. if (!query)
  1350. return query;
  1351. query = query.trim();
  1352. var lineNumberMatch = query.match(/([^:]+)(\:[\d]*)$/);
  1353. this._queryLineNumber = lineNumberMatch ? lineNumberMatch[2] : "";
  1354. return lineNumberMatch ? lineNumberMatch[1] : query;
  1355. },
  1356.  
  1357. __proto__: WebInspector.SelectionDialogContentProvider.prototype
  1358. }
  1359.  
  1360.  
  1361. WebInspector.OpenResourceDialog.show = function(panel, uiSourceCodeProvider, relativeToElement)
  1362. {
  1363. if (WebInspector.Dialog.currentInstance())
  1364. return;
  1365.  
  1366. var filteredItemSelectionDialog = new WebInspector.FilteredItemSelectionDialog(new WebInspector.OpenResourceDialog(panel, uiSourceCodeProvider));
  1367. WebInspector.Dialog.show(relativeToElement, filteredItemSelectionDialog);
  1368. }
  1369. ;
  1370.  
  1371.  
  1372.  
  1373. WebInspector.JavaScriptSourceFrame = function(scriptsPanel, uiSourceCode)
  1374. {
  1375. this._scriptsPanel = scriptsPanel;
  1376. this._breakpointManager = WebInspector.breakpointManager;
  1377. this._uiSourceCode = uiSourceCode;
  1378.  
  1379. var locations = this._breakpointManager.breakpointLocationsForUISourceCode(this._uiSourceCode);
  1380. for (var i = 0; i < locations.length; ++i)
  1381. this._breakpointAdded({data:locations[i]});
  1382.  
  1383. WebInspector.SourceFrame.call(this, uiSourceCode);
  1384.  
  1385. this._popoverHelper = new WebInspector.ObjectPopoverHelper(this.textEditor.element,
  1386. this._getPopoverAnchor.bind(this), this._resolveObjectForPopover.bind(this), this._onHidePopover.bind(this), true);
  1387.  
  1388. this.textEditor.element.addEventListener("keydown", this._onKeyDown.bind(this), true);
  1389.  
  1390. this.textEditor.addEventListener(WebInspector.TextEditor.Events.GutterClick, this._handleGutterClick.bind(this), this);
  1391.  
  1392. this._breakpointManager.addEventListener(WebInspector.BreakpointManager.Events.BreakpointAdded, this._breakpointAdded, this);
  1393. this._breakpointManager.addEventListener(WebInspector.BreakpointManager.Events.BreakpointRemoved, this._breakpointRemoved, this);
  1394.  
  1395. this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.FormattedChanged, this._onFormattedChanged, this);
  1396. this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyChanged, this._onWorkingCopyChanged, this);
  1397. this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._onWorkingCopyCommitted, this);
  1398. this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.ConsoleMessageAdded, this._consoleMessageAdded, this);
  1399. this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.ConsoleMessageRemoved, this._consoleMessageRemoved, this);
  1400. this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.ConsoleMessagesCleared, this._consoleMessagesCleared, this);
  1401. this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.SourceMappingChanged, this._onSourceMappingChanged, this);
  1402.  
  1403. this._updateScriptFile();
  1404. }
  1405.  
  1406. WebInspector.JavaScriptSourceFrame.prototype = {
  1407.  
  1408. wasShown: function()
  1409. {
  1410. WebInspector.SourceFrame.prototype.wasShown.call(this);
  1411. },
  1412.  
  1413. willHide: function()
  1414. {
  1415. WebInspector.SourceFrame.prototype.willHide.call(this);
  1416. this._popoverHelper.hidePopover();
  1417. },
  1418.  
  1419.  
  1420. canEditSource: function()
  1421. {
  1422. return this._uiSourceCode.isEditable();
  1423. },
  1424.  
  1425.  
  1426. commitEditing: function(text)
  1427. {
  1428. if (!this._uiSourceCode.isDirty())
  1429. return;
  1430.  
  1431. this._isCommittingEditing = true;
  1432. this._uiSourceCode.commitWorkingCopy(function() { });
  1433. delete this._isCommittingEditing;
  1434. },
  1435.  
  1436.  
  1437. _onFormattedChanged: function(event)
  1438. {
  1439. var content =   (event.data.content);
  1440. this._textEditor.setReadOnly(this._uiSourceCode.formatted());
  1441. this.setContent(content, false, this._uiSourceCode.mimeType());
  1442. },
  1443.  
  1444.  
  1445. _onWorkingCopyChanged: function(event)
  1446. {
  1447. this._innerSetContent(this._uiSourceCode.workingCopy());
  1448. },
  1449.  
  1450.  
  1451. _onWorkingCopyCommitted: function(event)
  1452. {
  1453. this._innerSetContent(this._uiSourceCode.workingCopy());
  1454. },
  1455.  
  1456. _innerSetContent: function(content)
  1457. {
  1458. if (this._isSettingWorkingCopy || this._isCommittingEditing)
  1459. return;
  1460. var breakpointLocations = this._breakpointManager.breakpointLocationsForUISourceCode(this._uiSourceCode);
  1461. for (var i = 0; i < breakpointLocations.length; ++i)
  1462. breakpointLocations[i].breakpoint.remove();
  1463. this.setContent(content, false, this._uiSourceCode.mimeType());
  1464. },
  1465.  
  1466. populateLineGutterContextMenu: function(contextMenu, lineNumber)
  1467. {
  1468. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Continue to here" : "Continue to Here"), this._continueToLine.bind(this, lineNumber));
  1469.  
  1470. var breakpoint = this._breakpointManager.findBreakpoint(this._uiSourceCode, lineNumber);
  1471. if (!breakpoint) {
  1472.  
  1473. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Add breakpoint" : "Add Breakpoint"), this._setBreakpoint.bind(this, lineNumber, "", true));
  1474. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Add conditional breakpointΓǪ" : "Add Conditional BreakpointΓǪ"), this._editBreakpointCondition.bind(this, lineNumber));
  1475. } else {
  1476.  
  1477. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Remove breakpoint" : "Remove Breakpoint"), breakpoint.remove.bind(breakpoint));
  1478. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Edit breakpointΓǪ" : "Edit BreakpointΓǪ"), this._editBreakpointCondition.bind(this, lineNumber, breakpoint));
  1479. if (breakpoint.enabled())
  1480. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Disable breakpoint" : "Disable Breakpoint"), breakpoint.setEnabled.bind(breakpoint, false));
  1481. else
  1482. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Enable breakpoint" : "Enable Breakpoint"), breakpoint.setEnabled.bind(breakpoint, true));
  1483. }
  1484. },
  1485.  
  1486. populateTextAreaContextMenu: function(contextMenu, lineNumber)
  1487. {
  1488. WebInspector.SourceFrame.prototype.populateTextAreaContextMenu.call(this, contextMenu, lineNumber);
  1489. var selection = window.getSelection();
  1490. if (selection.type === "Range" && !selection.isCollapsed) {
  1491. var addToWatchLabel = WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Add to watch" : "Add to Watch");
  1492. contextMenu.appendItem(addToWatchLabel, this._scriptsPanel.addToWatch.bind(this._scriptsPanel, selection.toString()));
  1493. var evaluateLabel = WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Evaluate in console" : "Evaluate in Console");
  1494. contextMenu.appendItem(evaluateLabel, WebInspector.evaluateInConsole.bind(WebInspector, selection.toString()));
  1495. contextMenu.appendSeparator();
  1496. }
  1497. contextMenu.appendApplicableItems(this._uiSourceCode);
  1498. },
  1499.  
  1500. onTextChanged: function(oldRange, newRange)
  1501. {
  1502. WebInspector.SourceFrame.prototype.onTextChanged.call(this, oldRange, newRange);
  1503. this._isSettingWorkingCopy = true;
  1504. this._uiSourceCode.setWorkingCopy(this._textEditor.text());
  1505. delete this._isSettingWorkingCopy;
  1506. },
  1507.  
  1508. _willMergeToVM: function()
  1509. {
  1510. if (this._supportsEnabledBreakpointsWhileEditing())
  1511. return;
  1512. this._preserveDecorations = true;
  1513. },
  1514.  
  1515. _didMergeToVM: function()
  1516. {
  1517. if (this._supportsEnabledBreakpointsWhileEditing())
  1518. return;
  1519. delete this._preserveDecorations;
  1520. this._restoreBreakpointsAfterEditing();
  1521. },
  1522.  
  1523. _willDivergeFromVM: function()
  1524. {
  1525. if (this._supportsEnabledBreakpointsWhileEditing())
  1526. return;
  1527. this._preserveDecorations = true;
  1528. },
  1529.  
  1530. _didDivergeFromVM: function()
  1531. {
  1532. if (this._supportsEnabledBreakpointsWhileEditing())
  1533. return;
  1534. delete this._preserveDecorations;
  1535. this._muteBreakpointsWhileEditing();
  1536. },
  1537.  
  1538. _muteBreakpointsWhileEditing: function()
  1539. {
  1540. for (var lineNumber = 0; lineNumber < this._textEditor.linesCount; ++lineNumber) {
  1541. var breakpointDecoration = this._textEditor.getAttribute(lineNumber, "breakpoint");
  1542. if (!breakpointDecoration)
  1543. continue;
  1544. this._removeBreakpointDecoration(lineNumber);
  1545. this._addBreakpointDecoration(lineNumber, breakpointDecoration.condition, breakpointDecoration.enabled, true);
  1546. }
  1547. },
  1548.  
  1549. _supportsEnabledBreakpointsWhileEditing: function()
  1550. {
  1551. return this._uiSourceCode.isSnippet;
  1552. },
  1553.  
  1554. _restoreBreakpointsAfterEditing: function()
  1555. {
  1556. var breakpoints = {};
  1557.  
  1558. for (var lineNumber = 0; lineNumber < this._textEditor.linesCount; ++lineNumber) {
  1559. var breakpointDecoration = this._textEditor.getAttribute(lineNumber, "breakpoint");
  1560. if (breakpointDecoration) {
  1561. breakpoints[lineNumber] = breakpointDecoration;
  1562. this._removeBreakpointDecoration(lineNumber);
  1563. }
  1564. }
  1565.  
  1566.  
  1567. var breakpointLocations = this._breakpointManager.breakpointLocationsForUISourceCode(this._uiSourceCode);
  1568. var lineNumbers = {};
  1569. for (var i = 0; i < breakpointLocations.length; ++i) {
  1570. var breakpoint = breakpointLocations[i].breakpoint;
  1571. breakpointLocations[i].breakpoint.remove();
  1572. }
  1573.  
  1574.  
  1575. for (var lineNumberString in breakpoints) {
  1576. var lineNumber = parseInt(lineNumberString, 10);
  1577. if (isNaN(lineNumber))
  1578. continue;
  1579. var breakpointDecoration = breakpoints[lineNumberString];
  1580. this._setBreakpoint(lineNumber, breakpointDecoration.condition, breakpointDecoration.enabled);
  1581. }
  1582. },
  1583.  
  1584. _getPopoverAnchor: function(element, event)
  1585. {
  1586. if (!WebInspector.debuggerModel.isPaused())
  1587. return null;
  1588. if (window.getSelection().type === "Range")
  1589. return null;
  1590. var lineElement = element.enclosingNodeOrSelfWithClass("webkit-line-content");
  1591. if (!lineElement)
  1592. return null;
  1593.  
  1594. if (element.hasStyleClass("webkit-javascript-ident"))
  1595. return element;
  1596.  
  1597. if (element.hasStyleClass("source-frame-token"))
  1598. return element;
  1599.  
  1600.  
  1601. if (element.hasStyleClass("webkit-javascript-keyword"))
  1602. return element.textContent === "this" ? element : null;
  1603.  
  1604. if (element !== lineElement || lineElement.childElementCount)
  1605. return null;
  1606.  
  1607.  
  1608.  
  1609. var lineContent = lineElement.textContent;
  1610. var ranges = [];
  1611. var regex = new RegExp("[a-zA-Z_\$0-9]+", "g");
  1612. var match;
  1613. while (regex.lastIndex < lineContent.length && (match = regex.exec(lineContent)))
  1614. ranges.push({offset: match.index, length: regex.lastIndex - match.index});
  1615.  
  1616.  
  1617. var changes = [];
  1618. this.textEditor.highlightRangesWithStyleClass(lineElement, ranges, "source-frame-token", changes);
  1619. var lineOffsetLeft = lineElement.totalOffsetLeft();
  1620. for (var child = lineElement.firstChild; child; child = child.nextSibling) {
  1621. if (child.nodeType !== Node.ELEMENT_NODE || !child.hasStyleClass("source-frame-token"))
  1622. continue;
  1623. if (event.x > lineOffsetLeft + child.offsetLeft && event.x < lineOffsetLeft + child.offsetLeft + child.offsetWidth) {
  1624. var text = child.textContent;
  1625. return (text === "this" || !WebInspector.SourceJavaScriptTokenizer.Keywords[text]) ? child : null;
  1626. }
  1627. }
  1628. return null;
  1629. },
  1630.  
  1631. _resolveObjectForPopover: function(element, showCallback, objectGroupName)
  1632. {
  1633. this._highlightElement = this._highlightExpression(element);
  1634.  
  1635.  
  1636. function showObjectPopover(result, wasThrown)
  1637. {
  1638. if (!WebInspector.debuggerModel.isPaused()) {
  1639. this._popoverHelper.hidePopover();
  1640. return;
  1641. }
  1642. showCallback(WebInspector.RemoteObject.fromPayload(result), wasThrown, this._highlightElement);
  1643.  
  1644. if (this._highlightElement)
  1645. this._highlightElement.addStyleClass("source-frame-eval-expression");
  1646. }
  1647.  
  1648. if (!WebInspector.debuggerModel.isPaused()) {
  1649. this._popoverHelper.hidePopover();
  1650. return;
  1651. }
  1652. var selectedCallFrame = WebInspector.debuggerModel.selectedCallFrame();
  1653. selectedCallFrame.evaluate(this._highlightElement.textContent, objectGroupName, false, true, false, false, showObjectPopover.bind(this));
  1654. },
  1655.  
  1656. _onHidePopover: function()
  1657. {
  1658.  
  1659. var highlightElement = this._highlightElement;
  1660. if (!highlightElement)
  1661. return;
  1662.  
  1663.  
  1664. this.textEditor.hideHighlightedExpression(highlightElement);
  1665. delete this._highlightElement;
  1666. },
  1667.  
  1668.  
  1669. _highlightExpression: function(element)
  1670. {
  1671. return this.textEditor.highlightExpression(element, { "webkit-javascript-ident": true, "source-frame-token": true, "webkit-javascript-keyword": true }, { ".": true });
  1672. },
  1673.  
  1674.  
  1675. _addBreakpointDecoration: function(lineNumber, condition, enabled, mutedWhileEditing)
  1676. {
  1677. if (this._preserveDecorations)
  1678. return;
  1679. var breakpoint = {
  1680. condition: condition,
  1681. enabled: enabled
  1682. };
  1683. this.textEditor.setAttribute(lineNumber, "breakpoint", breakpoint);
  1684.  
  1685. var disabled = !enabled || mutedWhileEditing;
  1686. this.textEditor.addBreakpoint(lineNumber, disabled, !!condition);
  1687. },
  1688.  
  1689. _removeBreakpointDecoration: function(lineNumber)
  1690. {
  1691. if (this._preserveDecorations)
  1692. return;
  1693. this.textEditor.removeAttribute(lineNumber, "breakpoint");
  1694. this.textEditor.removeBreakpoint(lineNumber);
  1695. },
  1696.  
  1697. _onKeyDown: function(event)
  1698. {
  1699. if (event.keyIdentifier === "U+001B") { 
  1700. if (this._popoverHelper.isPopoverVisible()) {
  1701. this._popoverHelper.hidePopover();
  1702. event.consume();
  1703. }
  1704. }
  1705. },
  1706.  
  1707.  
  1708. _editBreakpointCondition: function(lineNumber, breakpoint)
  1709. {
  1710. this._conditionElement = this._createConditionElement(lineNumber);
  1711. this.textEditor.addDecoration(lineNumber, this._conditionElement);
  1712.  
  1713. function finishEditing(committed, element, newText)
  1714. {
  1715. this.textEditor.removeDecoration(lineNumber, this._conditionElement);
  1716. delete this._conditionEditorElement;
  1717. delete this._conditionElement;
  1718. if (breakpoint)
  1719. breakpoint.setCondition(newText);
  1720. else
  1721. this._setBreakpoint(lineNumber, newText, true);
  1722. }
  1723.  
  1724. var config = new WebInspector.EditingConfig(finishEditing.bind(this, true), finishEditing.bind(this, false));
  1725. WebInspector.startEditing(this._conditionEditorElement, config);
  1726. this._conditionEditorElement.value = breakpoint ? breakpoint.condition() : "";
  1727. this._conditionEditorElement.select();
  1728. },
  1729.  
  1730. _createConditionElement: function(lineNumber)
  1731. {
  1732. var conditionElement = document.createElement("div");
  1733. conditionElement.className = "source-frame-breakpoint-condition";
  1734.  
  1735. var labelElement = document.createElement("label");
  1736. labelElement.className = "source-frame-breakpoint-message";
  1737. labelElement.htmlFor = "source-frame-breakpoint-condition";
  1738. labelElement.appendChild(document.createTextNode(WebInspector.UIString("The breakpoint on line %d will stop only if this expression is true:", lineNumber)));
  1739. conditionElement.appendChild(labelElement);
  1740.  
  1741. var editorElement = document.createElement("input");
  1742. editorElement.id = "source-frame-breakpoint-condition";
  1743. editorElement.className = "monospace";
  1744. editorElement.type = "text";
  1745. conditionElement.appendChild(editorElement);
  1746. this._conditionEditorElement = editorElement;
  1747.  
  1748. return conditionElement;
  1749. },
  1750.  
  1751.  
  1752. setExecutionLine: function(lineNumber)
  1753. {
  1754. this._executionLineNumber = lineNumber;
  1755. if (this.loaded) {
  1756. this.textEditor.setExecutionLine(lineNumber);
  1757. this.revealLine(this._executionLineNumber);
  1758. if (this.canEditSource())
  1759. this.setSelection(WebInspector.TextRange.createFromLocation(lineNumber, 0));
  1760. }
  1761. },
  1762.  
  1763. clearExecutionLine: function()
  1764. {
  1765. if (this.loaded && typeof this._executionLineNumber === "number")
  1766. this.textEditor.clearExecutionLine();
  1767. delete this._executionLineNumber;
  1768. },
  1769.  
  1770. _lineNumberAfterEditing: function(lineNumber, oldRange, newRange)
  1771. {
  1772. var shiftOffset = lineNumber <= oldRange.startLine ? 0 : newRange.linesCount - oldRange.linesCount;
  1773.  
  1774.  
  1775. if (lineNumber === oldRange.startLine) {
  1776. var whiteSpacesRegex = /^[\s\xA0]*$/;
  1777. for (var i = 0; lineNumber + i <= newRange.endLine; ++i) {
  1778. if (!whiteSpacesRegex.test(this.textEditor.line(lineNumber + i))) {
  1779. shiftOffset = i;
  1780. break;
  1781. }
  1782. }
  1783. }
  1784.  
  1785. var newLineNumber = Math.max(0, lineNumber + shiftOffset);
  1786. if (oldRange.startLine < lineNumber && lineNumber < oldRange.endLine)
  1787. newLineNumber = oldRange.startLine;
  1788. return newLineNumber;
  1789. },
  1790.  
  1791. _breakpointAdded: function(event)
  1792. {
  1793. var uiLocation =   (event.data.uiLocation);
  1794.  
  1795. if (uiLocation.uiSourceCode !== this._uiSourceCode)
  1796. return;
  1797.  
  1798. var breakpoint =   (event.data.breakpoint);
  1799. if (this.loaded)
  1800. this._addBreakpointDecoration(uiLocation.lineNumber, breakpoint.condition(), breakpoint.enabled(), false);
  1801. },
  1802.  
  1803. _breakpointRemoved: function(event)
  1804. {
  1805. var uiLocation =   (event.data.uiLocation);
  1806. if (uiLocation.uiSourceCode !== this._uiSourceCode)
  1807. return;
  1808.  
  1809. var breakpoint =   (event.data.breakpoint);
  1810. var remainingBreakpoint = this._breakpointManager.findBreakpoint(this._uiSourceCode, uiLocation.lineNumber);
  1811. if (!remainingBreakpoint && this.loaded)
  1812. this._removeBreakpointDecoration(uiLocation.lineNumber);
  1813. },
  1814.  
  1815. _consoleMessageAdded: function(event)
  1816. {
  1817. var message =   (event.data);
  1818. if (this.loaded)
  1819. this.addMessageToSource(message.lineNumber, message.originalMessage);
  1820. },
  1821.  
  1822. _consoleMessageRemoved: function(event)
  1823. {
  1824. var message =   (event.data);
  1825. if (this.loaded)
  1826. this.removeMessageFromSource(message.lineNumber, message.originalMessage);
  1827. },
  1828.  
  1829. _consoleMessagesCleared: function(event)
  1830. {
  1831. this.clearMessages();
  1832. },
  1833.  
  1834.  
  1835. _onSourceMappingChanged: function(event)
  1836. {
  1837. this._updateScriptFile();
  1838. },
  1839.  
  1840. _updateScriptFile: function()
  1841. {
  1842. if (this._scriptFile) {
  1843. this._scriptFile.removeEventListener(WebInspector.ScriptFile.Events.WillMergeToVM, this._willMergeToVM, this);
  1844. this._scriptFile.removeEventListener(WebInspector.ScriptFile.Events.DidMergeToVM, this._didMergeToVM, this);
  1845. this._scriptFile.removeEventListener(WebInspector.ScriptFile.Events.WillDivergeFromVM, this._willDivergeFromVM, this);
  1846. this._scriptFile.removeEventListener(WebInspector.ScriptFile.Events.DidDivergeFromVM, this._didDivergeFromVM, this);
  1847. }
  1848. this._scriptFile = this._uiSourceCode.scriptFile();
  1849. if (this._scriptFile) {
  1850. this._scriptFile.addEventListener(WebInspector.ScriptFile.Events.WillMergeToVM, this._willMergeToVM, this);
  1851. this._scriptFile.addEventListener(WebInspector.ScriptFile.Events.DidMergeToVM, this._didMergeToVM, this);
  1852. this._scriptFile.addEventListener(WebInspector.ScriptFile.Events.WillDivergeFromVM, this._willDivergeFromVM, this);
  1853. this._scriptFile.addEventListener(WebInspector.ScriptFile.Events.DidDivergeFromVM, this._didDivergeFromVM, this);
  1854. }
  1855. },
  1856.  
  1857. onTextEditorContentLoaded: function()
  1858. {
  1859. if (typeof this._executionLineNumber === "number")
  1860. this.setExecutionLine(this._executionLineNumber);
  1861.  
  1862. var breakpointLocations = this._breakpointManager.breakpointLocationsForUISourceCode(this._uiSourceCode);
  1863. for (var i = 0; i < breakpointLocations.length; ++i) {
  1864. var breakpoint = breakpointLocations[i].breakpoint;
  1865. this._addBreakpointDecoration(breakpointLocations[i].uiLocation.lineNumber, breakpoint.condition(), breakpoint.enabled(), false);
  1866. }
  1867.  
  1868. var messages = this._uiSourceCode.consoleMessages();
  1869. for (var i = 0; i < messages.length; ++i) {
  1870. var message = messages[i];
  1871. this.addMessageToSource(message.lineNumber, message.originalMessage);
  1872. }
  1873. },
  1874.  
  1875.  
  1876. _handleGutterClick: function(event)
  1877. {
  1878. if (this._uiSourceCode.isDirty() && !this._supportsEnabledBreakpointsWhileEditing())
  1879. return;
  1880.  
  1881. var lineNumber = event.data.lineNumber;
  1882. var eventObject =   (event.data.event);
  1883.  
  1884. if (eventObject.button != 0 || eventObject.altKey || eventObject.ctrlKey || eventObject.metaKey)
  1885. return;
  1886.  
  1887. this._toggleBreakpoint(lineNumber, eventObject.shiftKey);
  1888. eventObject.consume(true);
  1889. },
  1890.  
  1891.  
  1892. _toggleBreakpoint: function(lineNumber, onlyDisable)
  1893. {
  1894. var breakpoint = this._breakpointManager.findBreakpoint(this._uiSourceCode, lineNumber);
  1895. if (breakpoint) {
  1896. if (onlyDisable)
  1897. breakpoint.setEnabled(!breakpoint.enabled());
  1898. else
  1899. breakpoint.remove();
  1900. } else
  1901. this._setBreakpoint(lineNumber, "", true);
  1902. },
  1903.  
  1904. toggleBreakpointOnCurrentLine: function()
  1905. {
  1906. var selection = this.textEditor.selection();
  1907. if (!selection)
  1908. return;
  1909. this._toggleBreakpoint(selection.startLine, false);
  1910. },
  1911.  
  1912.  
  1913. _setBreakpoint: function(lineNumber, condition, enabled)
  1914. {
  1915. this._breakpointManager.setBreakpoint(this._uiSourceCode, lineNumber, condition, enabled);
  1916.  
  1917. WebInspector.notifications.dispatchEventToListeners(WebInspector.UserMetrics.UserAction, {
  1918. action: WebInspector.UserMetrics.UserActionNames.SetBreakpoint,
  1919. url: this._uiSourceCode.url,
  1920. line: lineNumber,
  1921. enabled: enabled
  1922. });
  1923. },
  1924.  
  1925.  
  1926. _continueToLine: function(lineNumber)
  1927. {
  1928. var rawLocation =   (this._uiSourceCode.uiLocationToRawLocation(lineNumber, 0));
  1929. WebInspector.debuggerModel.continueToLocation(rawLocation);
  1930. },
  1931.  
  1932. __proto__: WebInspector.SourceFrame.prototype
  1933. }
  1934. ;
  1935.  
  1936.  
  1937.  
  1938. WebInspector.NavigatorOverlayController = function(parentSidebarView, navigatorView, editorView)
  1939. {
  1940. this._parentSidebarView = parentSidebarView;
  1941. this._navigatorView = navigatorView;
  1942. this._editorView = editorView;
  1943.  
  1944. this._navigatorSidebarResizeWidgetElement = document.createElement("div");
  1945. this._navigatorSidebarResizeWidgetElement.addStyleClass("scripts-navigator-resizer-widget");
  1946. this._parentSidebarView.installResizer(this._navigatorSidebarResizeWidgetElement);
  1947. this._navigatorView.element.appendChild(this._navigatorSidebarResizeWidgetElement);
  1948.  
  1949. this._navigatorShowHideButton = new WebInspector.StatusBarButton(WebInspector.UIString("Hide navigator"), "scripts-navigator-show-hide-button", 3);
  1950. this._navigatorShowHideButton.state = "pinned";
  1951. this._navigatorShowHideButton.addEventListener("click", this._toggleNavigator, this);
  1952. this._editorView.element.appendChild(this._navigatorShowHideButton.element);
  1953.  
  1954. WebInspector.settings.navigatorHidden = WebInspector.settings.createSetting("navigatorHidden", true);
  1955. if (WebInspector.settings.navigatorHidden.get())
  1956. this._toggleNavigator();
  1957. }
  1958.  
  1959. WebInspector.NavigatorOverlayController.prototype = {
  1960. wasShown: function()
  1961. {
  1962. window.setTimeout(this._maybeShowNavigatorOverlay.bind(this), 0);
  1963. },
  1964.  
  1965. _maybeShowNavigatorOverlay: function()
  1966. {
  1967. if (WebInspector.settings.navigatorHidden.get() && !WebInspector.settings.navigatorWasOnceHidden.get())
  1968. this.showNavigatorOverlay();
  1969. },
  1970.  
  1971. _toggleNavigator: function()
  1972. {
  1973. if (this._navigatorShowHideButton.state === "overlay")
  1974. this._pinNavigator();
  1975. else if (this._navigatorShowHideButton.state === "hidden")
  1976. this.showNavigatorOverlay();
  1977. else
  1978. this._hidePinnedNavigator();
  1979. },
  1980.  
  1981. _hidePinnedNavigator: function()
  1982. {
  1983. this._navigatorShowHideButton.state = "hidden";
  1984. this._navigatorShowHideButton.title = WebInspector.UIString("Show navigator");
  1985. this._parentSidebarView.element.appendChild(this._navigatorShowHideButton.element);
  1986.  
  1987. this._editorView.element.addStyleClass("navigator-hidden");
  1988. this._navigatorSidebarResizeWidgetElement.addStyleClass("hidden");
  1989.  
  1990. this._parentSidebarView.hideSidebarElement();
  1991. this._navigatorView.detach();
  1992. this._editorView.focus();
  1993.  
  1994. WebInspector.settings.navigatorWasOnceHidden.set(true);
  1995. WebInspector.settings.navigatorHidden.set(true);
  1996. },
  1997.  
  1998. _pinNavigator: function()
  1999. {
  2000. this._navigatorShowHideButton.state = "pinned";
  2001. this._navigatorShowHideButton.title = WebInspector.UIString("Hide navigator");
  2002.  
  2003. this._editorView.element.removeStyleClass("navigator-hidden");
  2004. this._navigatorSidebarResizeWidgetElement.removeStyleClass("hidden");
  2005. this._editorView.element.appendChild(this._navigatorShowHideButton.element);
  2006.  
  2007. this._innerHideNavigatorOverlay();
  2008. this._parentSidebarView.showSidebarElement();
  2009. this._navigatorView.show(this._parentSidebarView.sidebarElement);
  2010. this._navigatorView.focus();
  2011. WebInspector.settings.navigatorHidden.set(false);
  2012. },
  2013.  
  2014. showNavigatorOverlay: function()
  2015. {
  2016. if (this._navigatorShowHideButton.state === "overlay")
  2017. return;
  2018.  
  2019. this._navigatorShowHideButton.state = "overlay";
  2020. this._navigatorShowHideButton.title = WebInspector.UIString("Pin navigator");
  2021.  
  2022. this._sidebarOverlay = new WebInspector.SidebarOverlay(this._navigatorView, "scriptsPanelNavigatorOverlayWidth", Preferences.minScriptsSidebarWidth);
  2023. this._boundKeyDown = this._keyDown.bind(this);
  2024. this._sidebarOverlay.element.addEventListener("keydown", this._boundKeyDown, false);
  2025. var navigatorOverlayResizeWidgetElement = document.createElement("div");
  2026. navigatorOverlayResizeWidgetElement.addStyleClass("scripts-navigator-resizer-widget");
  2027. this._sidebarOverlay.resizerWidgetElement = navigatorOverlayResizeWidgetElement;
  2028.  
  2029. this._navigatorView.element.appendChild(this._navigatorShowHideButton.element);
  2030. this._boundContainingElementFocused = this._containingElementFocused.bind(this);
  2031. this._parentSidebarView.element.addEventListener("mousedown", this._boundContainingElementFocused, false);
  2032.  
  2033. this._sidebarOverlay.show(this._parentSidebarView.element);
  2034. this._navigatorView.focus();
  2035. },
  2036.  
  2037. _keyDown: function(event)
  2038. {
  2039. if (event.handled)
  2040. return;
  2041.  
  2042. if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Esc.code) {
  2043. this.hideNavigatorOverlay();
  2044. event.consume(true);
  2045. }
  2046. },
  2047.  
  2048. hideNavigatorOverlay: function()
  2049. {
  2050. if (this._navigatorShowHideButton.state !== "overlay")
  2051. return;
  2052.  
  2053. this._navigatorShowHideButton.state = "hidden";
  2054. this._navigatorShowHideButton.title = WebInspector.UIString("Show navigator");
  2055. this._parentSidebarView.element.appendChild(this._navigatorShowHideButton.element);
  2056.  
  2057. this._innerHideNavigatorOverlay();
  2058. this._editorView.focus();
  2059. },
  2060.  
  2061. _innerHideNavigatorOverlay: function()
  2062. {
  2063. this._parentSidebarView.element.removeEventListener("mousedown", this._boundContainingElementFocused, false);
  2064. this._sidebarOverlay.element.removeEventListener("keydown", this._boundKeyDown, false);
  2065. this._sidebarOverlay.hide();
  2066. },
  2067.  
  2068. _containingElementFocused: function(event)
  2069. {
  2070. if (!event.target.isSelfOrDescendant(this._sidebarOverlay.element))
  2071. this.hideNavigatorOverlay();
  2072. },
  2073.  
  2074. isNavigatorPinned: function()
  2075. {
  2076. return this._navigatorShowHideButton.state === "pinned";
  2077. },
  2078.  
  2079. isNavigatorHidden: function()
  2080. {
  2081. return this._navigatorShowHideButton.state === "hidden";
  2082. }
  2083. }
  2084. ;
  2085.  
  2086.  
  2087.  
  2088. WebInspector.NavigatorView = function()
  2089. {
  2090. WebInspector.View.call(this);
  2091. this.registerRequiredCSS("navigatorView.css");
  2092.  
  2093. this._treeSearchBoxElement = document.createElement("div");
  2094. this._treeSearchBoxElement.className = "navigator-tree-search-box";
  2095. this.element.appendChild(this._treeSearchBoxElement);
  2096.  
  2097. var scriptsTreeElement = document.createElement("ol");
  2098. this._scriptsTree = new WebInspector.NavigatorTreeOutline(this._treeSearchBoxElement, scriptsTreeElement);
  2099.  
  2100. var scriptsOutlineElement = document.createElement("div");
  2101. scriptsOutlineElement.addStyleClass("outline-disclosure");
  2102. scriptsOutlineElement.addStyleClass("navigator");
  2103. scriptsOutlineElement.appendChild(scriptsTreeElement);
  2104.  
  2105. this.element.addStyleClass("fill");
  2106. this.element.addStyleClass("navigator-container");
  2107. this.element.appendChild(scriptsOutlineElement);
  2108. this.setDefaultFocusedElement(this._scriptsTree.element);
  2109.  
  2110. this._folderTreeElements = {};
  2111. this._scriptTreeElementsByUISourceCode = new Map();
  2112.  
  2113. WebInspector.settings.showScriptFolders.addChangeListener(this._showScriptFoldersSettingChanged.bind(this));
  2114. }
  2115.  
  2116.  
  2117. WebInspector.NavigatorView.Events = {
  2118. ItemSelected: "ItemSelected",
  2119. FileRenamed: "FileRenamed"
  2120. }
  2121.  
  2122. WebInspector.NavigatorView.prototype = {
  2123.  
  2124. addUISourceCode: function(uiSourceCode)
  2125. {
  2126. if (this._scriptTreeElementsByUISourceCode.get(uiSourceCode))
  2127. return;
  2128.  
  2129. var scriptTreeElement = new WebInspector.NavigatorSourceTreeElement(this, uiSourceCode, "");
  2130. this._scriptTreeElementsByUISourceCode.put(uiSourceCode, scriptTreeElement);
  2131. this._updateScriptTitle(uiSourceCode);
  2132. this._addUISourceCodeListeners(uiSourceCode);
  2133.  
  2134. var folderTreeElement = this.getOrCreateFolderTreeElement(uiSourceCode);
  2135. folderTreeElement.appendChild(scriptTreeElement);
  2136. },
  2137.  
  2138. _uiSourceCodeTitleChanged: function(event)
  2139. {
  2140. var uiSourceCode =   (event.target);
  2141. this._updateScriptTitle(uiSourceCode)
  2142. },
  2143.  
  2144. _uiSourceCodeWorkingCopyChanged: function(event)
  2145. {
  2146. var uiSourceCode =   (event.target);
  2147. this._updateScriptTitle(uiSourceCode)
  2148. },
  2149.  
  2150. _uiSourceCodeWorkingCopyCommitted: function(event)
  2151. {
  2152. var uiSourceCode =   (event.target);
  2153. this._updateScriptTitle(uiSourceCode)
  2154. },
  2155.  
  2156. _uiSourceCodeFormattedChanged: function(event)
  2157. {
  2158. var uiSourceCode =   (event.target);
  2159. this._updateScriptTitle(uiSourceCode);
  2160. },
  2161.  
  2162.  
  2163. _updateScriptTitle: function(uiSourceCode, ignoreIsDirty)
  2164. {
  2165. var scriptTreeElement = this._scriptTreeElementsByUISourceCode.get(uiSourceCode);
  2166. if (!scriptTreeElement)
  2167. return;
  2168.  
  2169. var titleText;
  2170. if (uiSourceCode.parsedURL.isValid) {
  2171. titleText = uiSourceCode.parsedURL.lastPathComponent;
  2172. if (uiSourceCode.parsedURL.queryParams)
  2173. titleText += "?" + uiSourceCode.parsedURL.queryParams;
  2174. } else if (uiSourceCode.parsedURL)
  2175. titleText = uiSourceCode.parsedURL.url;
  2176. if (!titleText)
  2177. titleText = WebInspector.UIString("(program)");
  2178. if (!ignoreIsDirty && uiSourceCode.isDirty())
  2179. titleText = "*" + titleText;
  2180. scriptTreeElement.titleText = titleText;
  2181. },
  2182.  
  2183.  
  2184. isScriptSourceAdded: function(uiSourceCode)
  2185. {
  2186. var scriptTreeElement = this._scriptTreeElementsByUISourceCode.get(uiSourceCode);
  2187. return !!scriptTreeElement;
  2188. },
  2189.  
  2190.  
  2191. revealUISourceCode: function(uiSourceCode)
  2192. {
  2193. if (this._scriptsTree.selectedTreeElement)
  2194. this._scriptsTree.selectedTreeElement.deselect();
  2195.  
  2196. this._lastSelectedUISourceCode = uiSourceCode;
  2197.  
  2198. var scriptTreeElement = this._scriptTreeElementsByUISourceCode.get(uiSourceCode);
  2199. scriptTreeElement.revealAndSelect(true);
  2200. },
  2201.  
  2202.  
  2203. _scriptSelected: function(uiSourceCode, focusSource)
  2204. {
  2205. this._lastSelectedUISourceCode = uiSourceCode;
  2206. var data = { uiSourceCode: uiSourceCode, focusSource: focusSource};
  2207. this.dispatchEventToListeners(WebInspector.NavigatorView.Events.ItemSelected, data);
  2208. },
  2209.  
  2210.  
  2211. removeUISourceCode: function(uiSourceCode)
  2212. {
  2213. var treeElement = this._scriptTreeElementsByUISourceCode.get(uiSourceCode);
  2214. while (treeElement) {
  2215. var parent = treeElement.parent;
  2216. if (parent) {
  2217. if (treeElement instanceof WebInspector.NavigatorFolderTreeElement)
  2218. delete this._folderTreeElements[treeElement.folderIdentifier];
  2219. parent.removeChild(treeElement);
  2220. if (parent.children.length)
  2221. break;
  2222. }
  2223. treeElement = parent;
  2224. }
  2225. this._scriptTreeElementsByUISourceCode.remove(uiSourceCode);
  2226. this._removeUISourceCodeListeners(uiSourceCode);
  2227. },
  2228.  
  2229.  
  2230. _addUISourceCodeListeners: function(uiSourceCode)
  2231. {
  2232. uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.TitleChanged, this._uiSourceCodeTitleChanged, this);
  2233. uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyChanged, this._uiSourceCodeWorkingCopyChanged, this);
  2234. uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._uiSourceCodeWorkingCopyCommitted, this);
  2235. uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.FormattedChanged, this._uiSourceCodeFormattedChanged, this);
  2236. },
  2237.  
  2238.  
  2239. _removeUISourceCodeListeners: function(uiSourceCode)
  2240. {
  2241. uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.TitleChanged, this._uiSourceCodeTitleChanged, this);
  2242. uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.WorkingCopyChanged, this._uiSourceCodeWorkingCopyChanged, this);
  2243. uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._uiSourceCodeWorkingCopyCommitted, this);
  2244. uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.FormattedChanged, this._uiSourceCodeFormattedChanged, this);
  2245. },
  2246.  
  2247. _showScriptFoldersSettingChanged: function()
  2248. {
  2249. var uiSourceCodes = this._scriptsTree.scriptTreeElements();
  2250. this.reset();
  2251.  
  2252. for (var i = 0; i < uiSourceCodes.length; ++i)
  2253. this.addUISourceCode(uiSourceCodes[i]);
  2254.  
  2255. if (this._lastSelectedUISourceCode)
  2256. this.revealUISourceCode(this._lastSelectedUISourceCode);
  2257. },
  2258.  
  2259. _fileRenamed: function(uiSourceCode, newTitle)
  2260. {    
  2261. var data = { uiSourceCode: uiSourceCode, name: newTitle };
  2262. this.dispatchEventToListeners(WebInspector.NavigatorView.Events.FileRenamed, data);
  2263. },
  2264.  
  2265.  
  2266. rename: function(uiSourceCode, callback)
  2267. {
  2268. var scriptTreeElement = this._scriptTreeElementsByUISourceCode.get(uiSourceCode);
  2269. if (!scriptTreeElement)
  2270. return;
  2271.  
  2272.  
  2273. var treeOutlineElement = scriptTreeElement.treeOutline.element;
  2274. WebInspector.markBeingEdited(treeOutlineElement, true);
  2275.  
  2276. function commitHandler(element, newTitle, oldTitle)
  2277. {
  2278. if (newTitle && newTitle !== oldTitle)
  2279. this._fileRenamed(uiSourceCode, newTitle);
  2280. afterEditing.call(this, true);
  2281. }
  2282.  
  2283. function cancelHandler()
  2284. {
  2285. afterEditing.call(this, false);
  2286. }
  2287.  
  2288.  
  2289. function afterEditing(committed)
  2290. {
  2291. WebInspector.markBeingEdited(treeOutlineElement, false);
  2292. this._updateScriptTitle(uiSourceCode);
  2293. if (callback)
  2294. callback(committed);
  2295. }
  2296.  
  2297. var editingConfig = new WebInspector.EditingConfig(commitHandler.bind(this), cancelHandler.bind(this));
  2298. this._updateScriptTitle(uiSourceCode, true);
  2299. WebInspector.startEditing(scriptTreeElement.titleElement, editingConfig);
  2300. window.getSelection().setBaseAndExtent(scriptTreeElement.titleElement, 0, scriptTreeElement.titleElement, 1);
  2301. },
  2302.  
  2303. reset: function()
  2304. {
  2305. var uiSourceCodes = this._scriptsTree.scriptTreeElements;
  2306. for (var i = 0; i < uiSourceCodes.length; ++i)
  2307. this._removeUISourceCodeListeners(uiSourceCodes[i]);
  2308.  
  2309. this._scriptsTree.stopSearch();
  2310. this._scriptsTree.removeChildren();
  2311. this._folderTreeElements = {};
  2312. this._scriptTreeElementsByUISourceCode.clear();
  2313. },
  2314.  
  2315.  
  2316. createFolderTreeElement: function(parentFolderElement, folderIdentifier, domain, folderName)
  2317. {
  2318. var folderTreeElement = new WebInspector.NavigatorFolderTreeElement(folderIdentifier, domain, folderName);
  2319. parentFolderElement.appendChild(folderTreeElement);
  2320. this._folderTreeElements[folderIdentifier] = folderTreeElement;
  2321. return folderTreeElement;
  2322. },
  2323.  
  2324.  
  2325. getOrCreateFolderTreeElement: function(uiSourceCode)
  2326. {
  2327. return this._getOrCreateFolderTreeElement(uiSourceCode.parsedURL.host, uiSourceCode.parsedURL.folderPathComponents);
  2328. },
  2329.  
  2330.  
  2331. _getOrCreateFolderTreeElement: function(domain, folderName)
  2332. {
  2333. var folderIdentifier = domain + "/" + folderName;
  2334.  
  2335. if (this._folderTreeElements[folderIdentifier])
  2336. return this._folderTreeElements[folderIdentifier];
  2337.  
  2338. var showScriptFolders = WebInspector.settings.showScriptFolders.get();
  2339.  
  2340. if ((!domain && !folderName) || !showScriptFolders)
  2341. return this._scriptsTree;
  2342.  
  2343. var parentFolderElement;
  2344. if (!folderName)
  2345. parentFolderElement = this._scriptsTree;
  2346. else
  2347. parentFolderElement = this._getOrCreateFolderTreeElement(domain, "");
  2348.  
  2349. return this.createFolderTreeElement(parentFolderElement, folderIdentifier, domain, folderName);
  2350. },
  2351.  
  2352. handleContextMenu: function(event, uiSourceCode)
  2353. {
  2354. var contextMenu = new WebInspector.ContextMenu(event);
  2355. contextMenu.appendApplicableItems(uiSourceCode);
  2356. contextMenu.show();
  2357. },
  2358.  
  2359. __proto__: WebInspector.View.prototype
  2360. }
  2361.  
  2362.  
  2363. WebInspector.NavigatorTreeOutline = function(treeSearchBoxElement, element)
  2364. {
  2365. TreeOutline.call(this, element);
  2366. this.element = element;
  2367.  
  2368. this._treeSearchBoxElement = treeSearchBoxElement;
  2369.  
  2370. this.comparator = WebInspector.NavigatorTreeOutline._treeElementsCompare;
  2371.  
  2372. this.searchable = true;
  2373. this.searchInputElement = document.createElement("input");
  2374. }
  2375.  
  2376. WebInspector.NavigatorTreeOutline._treeElementsCompare = function compare(treeElement1, treeElement2)
  2377. {
  2378.  
  2379. function typeWeight(treeElement)
  2380. {
  2381. if (treeElement instanceof WebInspector.NavigatorFolderTreeElement) {
  2382. if (treeElement.isDomain) {
  2383. if (treeElement.titleText === WebInspector.inspectedPageDomain)
  2384. return 1;
  2385. return 2;
  2386. }
  2387. return 3;
  2388. }
  2389. return 4;
  2390. }
  2391.  
  2392. var typeWeight1 = typeWeight(treeElement1);
  2393. var typeWeight2 = typeWeight(treeElement2);
  2394.  
  2395. var result;
  2396. if (typeWeight1 > typeWeight2)
  2397. result = 1;
  2398. else if (typeWeight1 < typeWeight2)
  2399. result = -1;
  2400. else {
  2401. var title1 = treeElement1.titleText;
  2402. var title2 = treeElement2.titleText;
  2403. result = title1.localeCompare(title2);
  2404. }
  2405. return result;
  2406. }
  2407.  
  2408. WebInspector.NavigatorTreeOutline.prototype = {
  2409.  
  2410. scriptTreeElements: function()
  2411. {
  2412. var result = [];
  2413. if (this.children.length) {
  2414. for (var treeElement = this.children[0]; treeElement; treeElement = treeElement.traverseNextTreeElement(false, this, true)) {
  2415. if (treeElement instanceof WebInspector.NavigatorSourceTreeElement)
  2416. result.push(treeElement.uiSourceCode);
  2417. }
  2418. }
  2419. return result;
  2420. },
  2421.  
  2422. searchStarted: function()
  2423. {
  2424. this._treeSearchBoxElement.appendChild(this.searchInputElement);
  2425. this._treeSearchBoxElement.addStyleClass("visible");
  2426. },
  2427.  
  2428. searchFinished: function()
  2429. {
  2430. this._treeSearchBoxElement.removeChild(this.searchInputElement);
  2431. this._treeSearchBoxElement.removeStyleClass("visible");
  2432. },
  2433.  
  2434. __proto__: TreeOutline.prototype
  2435. }
  2436.  
  2437.  
  2438. WebInspector.BaseNavigatorTreeElement = function(title, iconClasses, hasChildren, noIcon)
  2439. {
  2440. TreeElement.call(this, "", null, hasChildren);
  2441. this._titleText = title;
  2442. this._iconClasses = iconClasses;
  2443. this._noIcon = noIcon;
  2444. }
  2445.  
  2446. WebInspector.BaseNavigatorTreeElement.prototype = {
  2447. onattach: function()
  2448. {
  2449. this.listItemElement.removeChildren();
  2450. if (this._iconClasses) {
  2451. for (var i = 0; i < this._iconClasses.length; ++i)
  2452. this.listItemElement.addStyleClass(this._iconClasses[i]);
  2453. }
  2454.  
  2455. var selectionElement = document.createElement("div");
  2456. selectionElement.className = "selection";
  2457. this.listItemElement.appendChild(selectionElement);
  2458.  
  2459. if (!this._noIcon) {
  2460. this.imageElement = document.createElement("img");
  2461. this.imageElement.className = "icon";
  2462. this.listItemElement.appendChild(this.imageElement);
  2463. }
  2464.  
  2465. this.titleElement = document.createElement("div");
  2466. this.titleElement.className = "base-navigator-tree-element-title";
  2467. this._titleTextNode = document.createTextNode("");
  2468. this._titleTextNode.textContent = this._titleText;
  2469. this.titleElement.appendChild(this._titleTextNode);
  2470. this.listItemElement.appendChild(this.titleElement);
  2471. this.expand();
  2472. },
  2473.  
  2474. onreveal: function()
  2475. {
  2476. if (this.listItemElement)
  2477. this.listItemElement.scrollIntoViewIfNeeded(true);
  2478. },
  2479.  
  2480.  
  2481. get titleText()
  2482. {
  2483. return this._titleText;
  2484. },
  2485.  
  2486. set titleText(titleText)
  2487. {
  2488. if (this._titleText === titleText)
  2489. return;
  2490. this._titleText = titleText || "";
  2491. if (this.titleElement)
  2492. this.titleElement.textContent = this._titleText;
  2493. },
  2494.  
  2495.  
  2496. matchesSearchText: function(searchText)
  2497. {
  2498. return this.titleText.match(new RegExp("^" + searchText.escapeForRegExp(), "i"));
  2499. },
  2500.  
  2501. __proto__: TreeElement.prototype
  2502. }
  2503.  
  2504.  
  2505. WebInspector.NavigatorFolderTreeElement = function(folderIdentifier, domain, folderName)
  2506. {
  2507. this._folderIdentifier = folderIdentifier;
  2508. this._folderName = folderName;
  2509.  
  2510. var iconClass = this.isDomain ? "navigator-domain-tree-item" : "navigator-folder-tree-item";
  2511. var title = this.isDomain ? domain : folderName.substring(1);
  2512.  
  2513. WebInspector.BaseNavigatorTreeElement.call(this, title, [iconClass], true);
  2514. this.tooltip = folderName;
  2515. }
  2516.  
  2517. WebInspector.NavigatorFolderTreeElement.prototype = {
  2518.  
  2519. get folderIdentifier()
  2520. {
  2521. return this._folderIdentifier;
  2522. },
  2523.  
  2524.  
  2525. get isDomain()
  2526. {
  2527. return this._folderName === "";
  2528. },
  2529.  
  2530. onattach: function()
  2531. {
  2532. WebInspector.BaseNavigatorTreeElement.prototype.onattach.call(this);
  2533. if (this.isDomain && this.titleText != WebInspector.inspectedPageDomain)
  2534. this.collapse();
  2535. else
  2536. this.expand();
  2537. },
  2538.  
  2539. __proto__: WebInspector.BaseNavigatorTreeElement.prototype
  2540. }
  2541.  
  2542.  
  2543. WebInspector.NavigatorSourceTreeElement = function(navigatorView, uiSourceCode, title)
  2544. {
  2545. WebInspector.BaseNavigatorTreeElement.call(this, title, ["navigator-" + uiSourceCode.contentType().name() + "-tree-item"], false);
  2546. this._navigatorView = navigatorView;
  2547. this._uiSourceCode = uiSourceCode;
  2548. this.tooltip = uiSourceCode.url;
  2549. }
  2550.  
  2551. WebInspector.NavigatorSourceTreeElement.prototype = {
  2552.  
  2553. get uiSourceCode()
  2554. {
  2555. return this._uiSourceCode;
  2556. },
  2557.  
  2558. onattach: function()
  2559. {
  2560. WebInspector.BaseNavigatorTreeElement.prototype.onattach.call(this);
  2561. this.listItemElement.draggable = true;
  2562. this.listItemElement.addEventListener("click", this._onclick.bind(this), false);
  2563. this.listItemElement.addEventListener("contextmenu", this._handleContextMenuEvent.bind(this), false);
  2564. this.listItemElement.addEventListener("mousedown", this._onmousedown.bind(this), false);
  2565. this.listItemElement.addEventListener("dragstart", this._ondragstart.bind(this), false);
  2566. },
  2567.  
  2568. _onmousedown: function(event)
  2569. {
  2570. if (event.which === 1) 
  2571. this._uiSourceCode.requestContent(callback.bind(this));
  2572.  
  2573. function callback(content, contentEncoded, mimeType)
  2574. {
  2575. this._warmedUpContent = content;
  2576. }
  2577. },
  2578.  
  2579. _ondragstart: function(event)
  2580. {
  2581. event.dataTransfer.setData("text/plain", this._warmedUpContent);
  2582. event.dataTransfer.effectAllowed = "copy";
  2583. return true;
  2584. },
  2585.  
  2586. onspace: function()
  2587. {
  2588. this._navigatorView._scriptSelected(this.uiSourceCode, true);
  2589. return true;
  2590. },
  2591.  
  2592.  
  2593. _onclick: function(event)
  2594. {
  2595. this._navigatorView._scriptSelected(this.uiSourceCode, false);
  2596. },
  2597.  
  2598.  
  2599. ondblclick: function(event)
  2600. {
  2601. var middleClick = event.button === 1;
  2602. this._navigatorView._scriptSelected(this.uiSourceCode, !middleClick);
  2603. },
  2604.  
  2605. onenter: function()
  2606. {
  2607. this._navigatorView._scriptSelected(this.uiSourceCode, true);
  2608. return true;
  2609. },
  2610.  
  2611.  
  2612. _handleContextMenuEvent: function(event)
  2613. {
  2614. this._navigatorView.handleContextMenu(event, this._uiSourceCode);
  2615. },
  2616.  
  2617. __proto__: WebInspector.BaseNavigatorTreeElement.prototype
  2618. }
  2619. ;
  2620.  
  2621.  
  2622.  
  2623. WebInspector.RevisionHistoryView = function()
  2624. {
  2625. WebInspector.View.call(this);
  2626. this.registerRequiredCSS("revisionHistory.css");
  2627. this.element.addStyleClass("revision-history-drawer");
  2628. this.element.addStyleClass("fill");
  2629. this.element.addStyleClass("outline-disclosure");
  2630. this._uiSourceCodeItems = new Map();
  2631.  
  2632. var olElement = this.element.createChild("ol");
  2633. this._treeOutline = new TreeOutline(olElement);
  2634.  
  2635.  
  2636. function populateRevisions(uiSourceCode)
  2637. {
  2638. if (uiSourceCode.history.length)
  2639. this._createUISourceCodeItem(uiSourceCode);
  2640. }
  2641.  
  2642. WebInspector.workspace.uiSourceCodes().forEach(populateRevisions.bind(this));
  2643. WebInspector.workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeContentCommitted, this._revisionAdded, this);
  2644. WebInspector.workspace.addEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeRemoved, this._uiSourceCodeRemoved, this);
  2645. WebInspector.workspace.addEventListener(WebInspector.UISourceCodeProvider.Events.TemporaryUISourceCodeRemoved, this._uiSourceCodeRemoved, this);
  2646. WebInspector.workspace.addEventListener(WebInspector.Workspace.Events.ProjectWillReset, this._reset, this);
  2647.  
  2648. this._statusElement = document.createElement("span");
  2649. this._statusElement.textContent = WebInspector.UIString("Local modifications");
  2650.  
  2651. }
  2652.  
  2653.  
  2654. WebInspector.RevisionHistoryView.showHistory = function(uiSourceCode)
  2655. {
  2656. if (!WebInspector.RevisionHistoryView._view) 
  2657. WebInspector.RevisionHistoryView._view = new WebInspector.RevisionHistoryView();
  2658. var view = WebInspector.RevisionHistoryView._view;
  2659. WebInspector.showViewInDrawer(view._statusElement, view);
  2660. view._revealUISourceCode(uiSourceCode);
  2661. }
  2662.  
  2663. WebInspector.RevisionHistoryView.prototype = {
  2664.  
  2665. _createUISourceCodeItem: function(uiSourceCode)
  2666. {
  2667. var uiSourceCodeItem = new TreeElement(uiSourceCode.parsedURL.displayName, null, true);
  2668. uiSourceCodeItem.selectable = false;
  2669.  
  2670.  
  2671. for (var i = 0; i < this._treeOutline.children.length; ++i) {
  2672. if (this._treeOutline.children[i].title.localeCompare(uiSourceCode.parsedURL.displayName) > 0) {
  2673. this._treeOutline.insertChild(uiSourceCodeItem, i);
  2674. break;
  2675. }
  2676. }
  2677. if (i === this._treeOutline.children.length)
  2678. this._treeOutline.appendChild(uiSourceCodeItem);
  2679.  
  2680. this._uiSourceCodeItems.put(uiSourceCode, uiSourceCodeItem);
  2681.  
  2682. var revisionCount = uiSourceCode.history.length;
  2683. for (var i = revisionCount - 1; i >= 0; --i) {
  2684. var revision = uiSourceCode.history[i];
  2685. var historyItem = new WebInspector.RevisionHistoryTreeElement(revision, uiSourceCode.history[i - 1], i !== revisionCount - 1);
  2686. uiSourceCodeItem.appendChild(historyItem);
  2687. }
  2688.  
  2689. var linkItem = new TreeElement("", null, false);
  2690. linkItem.selectable = false;
  2691. uiSourceCodeItem.appendChild(linkItem);
  2692.  
  2693. var revertToOriginal = linkItem.listItemElement.createChild("span", "revision-history-link revision-history-link-row");
  2694. revertToOriginal.textContent = WebInspector.UIString("apply original content");
  2695. revertToOriginal.addEventListener("click", uiSourceCode.revertToOriginal.bind(uiSourceCode));
  2696.  
  2697. var clearHistoryElement = uiSourceCodeItem.listItemElement.createChild("span", "revision-history-link");
  2698. clearHistoryElement.textContent = WebInspector.UIString("revert");
  2699. clearHistoryElement.addEventListener("click", this._clearHistory.bind(this, uiSourceCode));
  2700. return uiSourceCodeItem;
  2701. },
  2702.  
  2703.  
  2704. _clearHistory: function(uiSourceCode)
  2705. {
  2706. uiSourceCode.revertAndClearHistory(this._removeUISourceCode.bind(this));
  2707. },
  2708.  
  2709. _revisionAdded: function(event)
  2710. {
  2711. var uiSourceCode =   (event.data.uiSourceCode);
  2712. var uiSourceCodeItem = this._uiSourceCodeItems.get(uiSourceCode);
  2713. if (!uiSourceCodeItem) {
  2714. uiSourceCodeItem = this._createUISourceCodeItem(uiSourceCode);
  2715. return;
  2716. }
  2717.  
  2718. var historyLength = uiSourceCode.history.length;
  2719. var historyItem = new WebInspector.RevisionHistoryTreeElement(uiSourceCode.history[historyLength - 1], uiSourceCode.history[historyLength - 2], false);
  2720. if (uiSourceCodeItem.children.length)
  2721. uiSourceCodeItem.children[0].allowRevert();
  2722. uiSourceCodeItem.insertChild(historyItem, 0);
  2723. },
  2724.  
  2725.  
  2726. _revealUISourceCode: function(uiSourceCode)
  2727. {
  2728. var uiSourceCodeItem = this._uiSourceCodeItems.get(uiSourceCode);
  2729. if (uiSourceCodeItem) {
  2730. uiSourceCodeItem.reveal();
  2731. uiSourceCodeItem.expand();
  2732. }
  2733. },
  2734.  
  2735. _uiSourceCodeRemoved: function(event)
  2736. {
  2737. var uiSourceCode =   (event.data);
  2738. this._removeUISourceCode(uiSourceCode);
  2739. },
  2740.  
  2741.  
  2742. _removeUISourceCode: function(uiSourceCode)
  2743. {
  2744. var uiSourceCodeItem = this._uiSourceCodeItems.get(uiSourceCode);
  2745. if (!uiSourceCodeItem)
  2746. return;
  2747. this._treeOutline.removeChild(uiSourceCodeItem);
  2748. this._uiSourceCodeItems.remove(uiSourceCode);
  2749. },
  2750.  
  2751. _reset: function()
  2752. {
  2753. this._treeOutline.removeChildren();
  2754. this._uiSourceCodeItems.clear();
  2755. },
  2756.  
  2757. __proto__: WebInspector.View.prototype
  2758. }
  2759.  
  2760.  
  2761. WebInspector.RevisionHistoryTreeElement = function(revision, baseRevision, allowRevert)
  2762. {
  2763. TreeElement.call(this, revision.timestamp.toLocaleTimeString(), null, true);
  2764. this.selectable = false;
  2765.  
  2766. this._revision = revision;
  2767. this._baseRevision = baseRevision;
  2768.  
  2769. this._revertElement = document.createElement("span");
  2770. this._revertElement.className = "revision-history-link";
  2771. this._revertElement.textContent = WebInspector.UIString("apply revision content");
  2772. this._revertElement.addEventListener("click", this._revision.revertToThis.bind(this._revision), false);
  2773. if (!allowRevert)
  2774. this._revertElement.addStyleClass("hidden");
  2775. }
  2776.  
  2777. WebInspector.RevisionHistoryTreeElement.prototype = {
  2778. onattach: function()
  2779. {
  2780. this.listItemElement.addStyleClass("revision-history-revision");
  2781. },
  2782.  
  2783. onexpand: function()
  2784. {
  2785. this.listItemElement.appendChild(this._revertElement);
  2786.  
  2787. if (this._wasExpandedOnce)
  2788. return;
  2789. this._wasExpandedOnce = true;
  2790.  
  2791. this.childrenListElement.addStyleClass("source-code");
  2792. if (this._baseRevision)
  2793. this._baseRevision.requestContent(step1.bind(this));
  2794. else
  2795. this._revision.uiSourceCode.requestOriginalContent(step1.bind(this));
  2796.  
  2797. function step1(baseContent)
  2798. {
  2799. this._revision.requestContent(step2.bind(this, baseContent));
  2800. }
  2801.  
  2802. function step2(baseContent, newContent)
  2803. {
  2804. var baseLines = difflib.stringAsLines(baseContent);
  2805. var newLines = difflib.stringAsLines(newContent);
  2806. var sm = new difflib.SequenceMatcher(baseLines, newLines);
  2807. var opcodes = sm.get_opcodes();
  2808. var lastWasSeparator = false;
  2809.  
  2810. for (var idx = 0; idx < opcodes.length; idx++) {
  2811. var code = opcodes[idx];
  2812. var change = code[0];
  2813. var b = code[1];
  2814. var be = code[2];
  2815. var n = code[3];
  2816. var ne = code[4];
  2817. var rowCount = Math.max(be - b, ne - n);
  2818. var topRows = [];
  2819. var bottomRows = [];
  2820. for (var i = 0; i < rowCount; i++) {
  2821. if (change === "delete" || (change === "replace" && b < be)) {
  2822. var lineNumber = b++;
  2823. this._createLine(lineNumber, null, baseLines[lineNumber], "removed");
  2824. lastWasSeparator = false;
  2825. }
  2826.  
  2827. if (change === "insert" || (change === "replace" && n < ne)) {
  2828. var lineNumber = n++;
  2829. this._createLine(null, lineNumber, newLines[lineNumber], "added");
  2830. lastWasSeparator = false;
  2831. }
  2832.  
  2833. if (change === "equal") {
  2834. b++;
  2835. n++;
  2836. if (!lastWasSeparator)
  2837. this._createLine(null, null, "    \u2026", "separator");
  2838. lastWasSeparator = true;
  2839. }
  2840. }
  2841. }
  2842. }
  2843. },
  2844.  
  2845. oncollapse: function()
  2846. {
  2847. if (this._revertElement.parentElement)
  2848. this._revertElement.parentElement.removeChild(this._revertElement);
  2849. },
  2850.  
  2851.  
  2852. _createLine: function(baseLineNumber, newLineNumber, lineContent, changeType)
  2853. {
  2854. var child = new TreeElement("", null, false);
  2855. child.selectable = false;
  2856. this.appendChild(child);
  2857. var lineElement = document.createElement("span");
  2858.  
  2859. function appendLineNumber(lineNumber)
  2860. {
  2861. var numberString = lineNumber !== null ? numberToStringWithSpacesPadding(lineNumber + 1, 4) : "    ";
  2862. var lineNumberSpan = document.createElement("span");
  2863. lineNumberSpan.addStyleClass("webkit-line-number");
  2864. lineNumberSpan.textContent = numberString;
  2865. child.listItemElement.appendChild(lineNumberSpan);
  2866. }
  2867.  
  2868. appendLineNumber(baseLineNumber);
  2869. appendLineNumber(newLineNumber);
  2870.  
  2871. var contentSpan = document.createElement("span");
  2872. contentSpan.textContent = lineContent;
  2873. child.listItemElement.appendChild(contentSpan);
  2874. child.listItemElement.addStyleClass("revision-history-line");
  2875. child.listItemElement.addStyleClass("revision-history-line-" + changeType);
  2876. },
  2877.  
  2878. allowRevert: function()
  2879. {
  2880. this._revertElement.removeStyleClass("hidden");
  2881. },
  2882.  
  2883. __proto__: TreeElement.prototype
  2884. }
  2885. ;
  2886.  
  2887.  
  2888.  
  2889. WebInspector.ScopeChainSidebarPane = function()
  2890. {
  2891. WebInspector.SidebarPane.call(this, WebInspector.UIString("Scope Variables"));
  2892. this._sections = [];
  2893. this._expandedSections = {};
  2894. this._expandedProperties = [];
  2895. }
  2896.  
  2897. WebInspector.ScopeChainSidebarPane.prototype = {
  2898. update: function(callFrame)
  2899. {
  2900. this.bodyElement.removeChildren();
  2901.  
  2902. if (!callFrame) {
  2903. var infoElement = document.createElement("div");
  2904. infoElement.className = "info";
  2905. infoElement.textContent = WebInspector.UIString("Not Paused");
  2906. this.bodyElement.appendChild(infoElement);
  2907. return;
  2908. }
  2909.  
  2910. for (var i = 0; i < this._sections.length; ++i) {
  2911. var section = this._sections[i];
  2912. if (!section.title)
  2913. continue;
  2914. if (section.expanded)
  2915. this._expandedSections[section.title] = true;
  2916. else
  2917. delete this._expandedSections[section.title];
  2918. }
  2919.  
  2920. this._sections = [];
  2921.  
  2922. var foundLocalScope = false;
  2923. var scopeChain = callFrame.scopeChain;
  2924. for (var i = 0; i < scopeChain.length; ++i) {
  2925. var scope = scopeChain[i];
  2926. var title = null;
  2927. var subtitle = scope.object.description;
  2928. var emptyPlaceholder = null;
  2929. var extraProperties = null;
  2930.  
  2931. switch (scope.type) {
  2932. case "local":
  2933. foundLocalScope = true;
  2934. title = WebInspector.UIString("Local");
  2935. emptyPlaceholder = WebInspector.UIString("No Variables");
  2936. subtitle = null;
  2937. if (callFrame.this)
  2938. extraProperties = [ new WebInspector.RemoteObjectProperty("this", WebInspector.RemoteObject.fromPayload(callFrame.this)) ];
  2939. if (i == 0) {
  2940. var details = WebInspector.debuggerModel.debuggerPausedDetails();
  2941. var exception = details.reason === WebInspector.DebuggerModel.BreakReason.Exception ? details.auxData : 0;
  2942. if (exception) {
  2943. extraProperties = extraProperties || [];
  2944. var exceptionObject =   (exception);
  2945. extraProperties.push(new WebInspector.RemoteObjectProperty("<exception>", WebInspector.RemoteObject.fromPayload(exceptionObject)));
  2946. }
  2947. }
  2948. break;
  2949. case "closure":
  2950. title = WebInspector.UIString("Closure");
  2951. emptyPlaceholder = WebInspector.UIString("No Variables");
  2952. subtitle = null;
  2953. break;
  2954. case "catch":
  2955. title = WebInspector.UIString("Catch");
  2956. subtitle = null;
  2957. break;
  2958. case "with":
  2959. title = WebInspector.UIString("With Block");
  2960. break;
  2961. case "global":
  2962. title = WebInspector.UIString("Global");
  2963. break;
  2964. }
  2965.  
  2966. if (!title || title === subtitle)
  2967. subtitle = null;
  2968.  
  2969. var section = new WebInspector.ObjectPropertiesSection(WebInspector.RemoteObject.fromPayload(scope.object), title, subtitle, emptyPlaceholder, true, extraProperties, WebInspector.ScopeVariableTreeElement);
  2970. section.editInSelectedCallFrameWhenPaused = true;
  2971. section.pane = this;
  2972.  
  2973. if (scope.type === "global")
  2974. section.expanded = false;
  2975. else if (!foundLocalScope || scope.type === "local" || title in this._expandedSections)
  2976. section.expanded = true;
  2977.  
  2978. this._sections.push(section);
  2979. this.bodyElement.appendChild(section.element);
  2980. }
  2981. },
  2982.  
  2983. __proto__: WebInspector.SidebarPane.prototype
  2984. }
  2985.  
  2986.  
  2987. WebInspector.ScopeVariableTreeElement = function(property)
  2988. {
  2989. WebInspector.ObjectPropertyTreeElement.call(this, property);
  2990. }
  2991.  
  2992. WebInspector.ScopeVariableTreeElement.prototype = {
  2993. onattach: function()
  2994. {
  2995. WebInspector.ObjectPropertyTreeElement.prototype.onattach.call(this);
  2996. if (this.hasChildren && this.propertyIdentifier in this.treeOutline.section.pane._expandedProperties)
  2997. this.expand();
  2998. },
  2999.  
  3000. onexpand: function()
  3001. {
  3002. this.treeOutline.section.pane._expandedProperties[this.propertyIdentifier] = true;
  3003. },
  3004.  
  3005. oncollapse: function()
  3006. {
  3007. delete this.treeOutline.section.pane._expandedProperties[this.propertyIdentifier];
  3008. },
  3009.  
  3010. get propertyIdentifier()
  3011. {
  3012. if ("_propertyIdentifier" in this)
  3013. return this._propertyIdentifier;
  3014. var section = this.treeOutline.section;
  3015. this._propertyIdentifier = section.title + ":" + (section.subtitle ? section.subtitle + ":" : "") + this.propertyPath();
  3016. return this._propertyIdentifier;
  3017. },
  3018.  
  3019. __proto__: WebInspector.ObjectPropertyTreeElement.prototype
  3020. }
  3021. ;
  3022.  
  3023.  
  3024.  
  3025. WebInspector.ScriptsNavigator = function()
  3026. {
  3027. WebInspector.Object.call(this);
  3028.  
  3029. this._tabbedPane = new WebInspector.TabbedPane();
  3030. this._tabbedPane.shrinkableTabs = true;
  3031. this._tabbedPane.element.addStyleClass("navigator-tabbed-pane");
  3032.  
  3033. this._scriptsView = new WebInspector.NavigatorView();
  3034. this._scriptsView.addEventListener(WebInspector.NavigatorView.Events.ItemSelected, this._scriptSelected, this);
  3035.  
  3036. this._contentScriptsView = new WebInspector.NavigatorView();
  3037. this._contentScriptsView.addEventListener(WebInspector.NavigatorView.Events.ItemSelected, this._scriptSelected, this);
  3038.  
  3039. this._snippetsView = new WebInspector.SnippetsNavigatorView();
  3040. this._snippetsView.addEventListener(WebInspector.NavigatorView.Events.ItemSelected, this._scriptSelected, this);
  3041. this._snippetsView.addEventListener(WebInspector.NavigatorView.Events.FileRenamed, this._fileRenamed, this);
  3042. this._snippetsView.addEventListener(WebInspector.SnippetsNavigatorView.Events.SnippetCreationRequested, this._snippetCreationRequested, this);
  3043. this._snippetsView.addEventListener(WebInspector.SnippetsNavigatorView.Events.ItemRenamingRequested, this._itemRenamingRequested, this);
  3044.  
  3045. this._tabbedPane.appendTab(WebInspector.ScriptsNavigator.ScriptsTab, WebInspector.UIString("Sources"), this._scriptsView);
  3046. this._tabbedPane.selectTab(WebInspector.ScriptsNavigator.ScriptsTab);
  3047. this._tabbedPane.appendTab(WebInspector.ScriptsNavigator.ContentScriptsTab, WebInspector.UIString("Content scripts"), this._contentScriptsView);
  3048. if (WebInspector.experimentsSettings.snippetsSupport.isEnabled())
  3049. this._tabbedPane.appendTab(WebInspector.ScriptsNavigator.SnippetsTab, WebInspector.UIString("Snippets"), this._snippetsView);
  3050. }
  3051.  
  3052. WebInspector.ScriptsNavigator.Events = {
  3053. ScriptSelected: "ScriptSelected",
  3054. SnippetCreationRequested: "SnippetCreationRequested",
  3055. ItemRenamingRequested: "ItemRenamingRequested",
  3056. FileRenamed: "FileRenamed"
  3057. }
  3058.  
  3059. WebInspector.ScriptsNavigator.ScriptsTab = "scripts";
  3060. WebInspector.ScriptsNavigator.ContentScriptsTab = "contentScripts";
  3061. WebInspector.ScriptsNavigator.SnippetsTab = "snippets";
  3062.  
  3063. WebInspector.ScriptsNavigator.prototype = {
  3064.  
  3065. get view()
  3066. {
  3067. return this._tabbedPane;
  3068. },
  3069.  
  3070.  
  3071. _snippetsNavigatorViewForUISourceCode: function(uiSourceCode)
  3072. {
  3073. if (uiSourceCode.isContentScript)
  3074. return this._contentScriptsView;
  3075. else if (uiSourceCode.isSnippet)
  3076. return this._snippetsView;
  3077. else
  3078. return this._scriptsView;
  3079. },
  3080.  
  3081.  
  3082. addUISourceCode: function(uiSourceCode)
  3083. {
  3084. this._snippetsNavigatorViewForUISourceCode(uiSourceCode).addUISourceCode(uiSourceCode);
  3085. },
  3086.  
  3087.  
  3088. removeUISourceCode: function(uiSourceCode)
  3089. {
  3090. this._snippetsNavigatorViewForUISourceCode(uiSourceCode).removeUISourceCode(uiSourceCode);
  3091. },
  3092.  
  3093.  
  3094. isScriptSourceAdded: function(uiSourceCode)
  3095. {
  3096. return this._snippetsNavigatorViewForUISourceCode(uiSourceCode).isScriptSourceAdded(uiSourceCode);
  3097. },
  3098.  
  3099.  
  3100. revealUISourceCode: function(uiSourceCode)
  3101. {
  3102. this._snippetsNavigatorViewForUISourceCode(uiSourceCode).revealUISourceCode(uiSourceCode);
  3103. if (uiSourceCode.isContentScript)
  3104. this._tabbedPane.selectTab(WebInspector.ScriptsNavigator.ContentScriptsTab);
  3105. else if (uiSourceCode.isSnippet)
  3106. this._tabbedPane.selectTab(WebInspector.ScriptsNavigator.SnippetsTab);
  3107. else
  3108. this._tabbedPane.selectTab(WebInspector.ScriptsNavigator.ScriptsTab);
  3109. },
  3110.  
  3111.  
  3112. rename: function(uiSourceCode, callback)
  3113. {
  3114. this._snippetsNavigatorViewForUISourceCode(uiSourceCode).rename(uiSourceCode, callback);
  3115. },
  3116.  
  3117.  
  3118. _scriptSelected: function(event)
  3119. {
  3120. this.dispatchEventToListeners(WebInspector.ScriptsNavigator.Events.ScriptSelected, event.data);
  3121. },
  3122.  
  3123.  
  3124. _fileRenamed: function(event)
  3125. {    
  3126. this.dispatchEventToListeners(WebInspector.ScriptsNavigator.Events.FileRenamed, event.data);
  3127. },
  3128.  
  3129.  
  3130. _itemRenamingRequested: function(event)
  3131. {
  3132. this.dispatchEventToListeners(WebInspector.ScriptsNavigator.Events.ItemRenamingRequested, event.data);
  3133. },
  3134.  
  3135.  
  3136. _snippetCreationRequested: function(event)
  3137. {    
  3138. this.dispatchEventToListeners(WebInspector.ScriptsNavigator.Events.SnippetCreationRequested, event.data);
  3139. },
  3140.  
  3141. reset: function()
  3142. {
  3143. this._scriptsView.reset();
  3144. this._contentScriptsView.reset();
  3145. this._snippetsView.reset();
  3146. },
  3147.  
  3148. __proto__: WebInspector.Object.prototype
  3149. }
  3150.  
  3151.  
  3152. WebInspector.SnippetsNavigatorView = function()
  3153. {
  3154. WebInspector.NavigatorView.call(this);
  3155. this.element.addEventListener("contextmenu", this.handleContextMenu.bind(this), false);
  3156. }
  3157.  
  3158. WebInspector.SnippetsNavigatorView.Events = {
  3159. SnippetCreationRequested: "SnippetCreationRequested",
  3160. ItemRenamingRequested: "ItemRenamingRequested"
  3161. }
  3162.  
  3163. WebInspector.SnippetsNavigatorView.prototype = {
  3164.  
  3165. getOrCreateFolderTreeElement: function(uiSourceCode)
  3166. {
  3167. return this._scriptsTree;
  3168. },
  3169.  
  3170.  
  3171. handleContextMenu: function(event, uiSourceCode)
  3172. {
  3173. var contextMenu = new WebInspector.ContextMenu(event);
  3174. if (uiSourceCode) {
  3175. contextMenu.appendItem(WebInspector.UIString("Run"), this._handleEvaluateSnippet.bind(this, uiSourceCode));
  3176. contextMenu.appendItem(WebInspector.UIString("Rename"), this._handleRenameSnippet.bind(this, uiSourceCode));
  3177. contextMenu.appendItem(WebInspector.UIString("Remove"), this._handleRemoveSnippet.bind(this, uiSourceCode));
  3178. contextMenu.appendSeparator();
  3179. }
  3180. contextMenu.appendItem(WebInspector.UIString("New"), this._handleCreateSnippet.bind(this));
  3181. contextMenu.show();
  3182. },
  3183.  
  3184.  
  3185. _handleEvaluateSnippet: function(uiSourceCode, event)
  3186. {
  3187. if (!uiSourceCode.isSnippet)
  3188. return;
  3189. WebInspector.scriptSnippetModel.evaluateScriptSnippet(uiSourceCode);
  3190. },
  3191.  
  3192.  
  3193. _handleRenameSnippet: function(uiSourceCode, event)
  3194. {
  3195. this.dispatchEventToListeners(WebInspector.ScriptsNavigator.Events.ItemRenamingRequested, uiSourceCode);
  3196. },
  3197.  
  3198.  
  3199. _handleRemoveSnippet: function(uiSourceCode, event)
  3200. {
  3201. if (!uiSourceCode.isSnippet)
  3202. return;
  3203. WebInspector.scriptSnippetModel.deleteScriptSnippet(uiSourceCode);
  3204. },
  3205.  
  3206.  
  3207. _handleCreateSnippet: function(event)
  3208. {
  3209. this._snippetCreationRequested();
  3210. },
  3211.  
  3212. _snippetCreationRequested: function()
  3213. {
  3214. this.dispatchEventToListeners(WebInspector.SnippetsNavigatorView.Events.SnippetCreationRequested, null);
  3215. },
  3216.  
  3217. __proto__: WebInspector.NavigatorView.prototype
  3218. }
  3219. ;
  3220.  
  3221.  
  3222.  
  3223. WebInspector.ScriptsSearchScope = function(uiSourceCodeProvider)
  3224. {
  3225.  
  3226. WebInspector.SearchScope.call(this)
  3227. this._searchId = 0;
  3228. this._uiSourceCodeProvider = uiSourceCodeProvider;
  3229. }
  3230.  
  3231. WebInspector.ScriptsSearchScope.prototype = {
  3232.  
  3233. performSearch: function(searchConfig, searchResultCallback, searchFinishedCallback)
  3234. {
  3235. this.stopSearch();
  3236.  
  3237. var uiSourceCodes = this._sortedUISourceCodes();
  3238. var uiSourceCodeIndex = 0;
  3239.  
  3240. function filterOutContentScripts(uiSourceCode)
  3241. {
  3242. return !uiSourceCode.isContentScript;
  3243. }
  3244.  
  3245. if (!WebInspector.settings.searchInContentScripts.get())
  3246. uiSourceCodes = uiSourceCodes.filter(filterOutContentScripts);
  3247.  
  3248. function continueSearch()
  3249. {
  3250.  
  3251.  
  3252. if (uiSourceCodeIndex < uiSourceCodes.length) {
  3253. var uiSourceCode = uiSourceCodes[uiSourceCodeIndex++];
  3254. uiSourceCode.searchInContent(searchConfig.query, !searchConfig.ignoreCase, searchConfig.isRegex, searchCallbackWrapper.bind(this, this._searchId, uiSourceCode));
  3255. } else 
  3256. searchFinishedCallback(true);
  3257. }
  3258.  
  3259. function searchCallbackWrapper(searchId, uiSourceCode, searchMatches)
  3260. {
  3261. if (searchId !== this._searchId) {
  3262. searchFinishedCallback(false);
  3263. return;
  3264. }
  3265. var searchResult = new WebInspector.FileBasedSearchResultsPane.SearchResult(uiSourceCode, searchMatches);
  3266. searchResultCallback(searchResult);
  3267. if (searchId !== this._searchId) {
  3268. searchFinishedCallback(false);
  3269. return;
  3270. }
  3271. continueSearch.call(this);
  3272. }
  3273.  
  3274. continueSearch.call(this);
  3275. return uiSourceCodes.length;
  3276. },
  3277.  
  3278. stopSearch: function()
  3279. {
  3280. ++this._searchId;
  3281. },
  3282.  
  3283.  
  3284. createSearchResultsPane: function(searchConfig)
  3285. {
  3286. return new WebInspector.FileBasedSearchResultsPane(searchConfig);
  3287. },
  3288.  
  3289.  
  3290. _sortedUISourceCodes: function()
  3291. {
  3292. function filterOutAnonymous(uiSourceCode)
  3293. {
  3294. return !!uiSourceCode.url;
  3295. }
  3296.  
  3297. function comparator(a, b)
  3298. {
  3299. return a.url.localeCompare(b.url);   
  3300. }
  3301.  
  3302. var uiSourceCodes = this._uiSourceCodeProvider.uiSourceCodes();
  3303.  
  3304. uiSourceCodes = uiSourceCodes.filter(filterOutAnonymous);
  3305. uiSourceCodes.sort(comparator);
  3306.  
  3307. return uiSourceCodes;
  3308. },
  3309.  
  3310. __proto__: WebInspector.SearchScope.prototype
  3311. }
  3312. ;
  3313.  
  3314.  
  3315.  
  3316. WebInspector.SnippetJavaScriptSourceFrame = function(scriptsPanel, uiSourceCode)
  3317. {
  3318. WebInspector.JavaScriptSourceFrame.call(this, scriptsPanel, uiSourceCode);
  3319.  
  3320. this._uiSourceCode = uiSourceCode;
  3321. this._runButton = new WebInspector.StatusBarButton(WebInspector.UIString("Run"), "evaluate-snippet-status-bar-item");
  3322. this._runButton.addEventListener("click", this._runButtonClicked, this);
  3323. }
  3324.  
  3325. WebInspector.SnippetJavaScriptSourceFrame.prototype = {
  3326.  
  3327. statusBarItems: function()
  3328. {
  3329. return [this._runButton.element];
  3330. },
  3331.  
  3332. _runButtonClicked: function()
  3333. {
  3334. WebInspector.scriptSnippetModel.evaluateScriptSnippet(this._uiSourceCode);
  3335. },
  3336.  
  3337. __proto__: WebInspector.JavaScriptSourceFrame.prototype
  3338. }
  3339. ;
  3340.  
  3341.  
  3342.  
  3343. WebInspector.StyleSheetOutlineDialog = function(view, uiSourceCode)
  3344. {
  3345. WebInspector.SelectionDialogContentProvider.call(this);
  3346.  
  3347. this._rules = [];
  3348. this._view = view;
  3349. this._uiSourceCode = uiSourceCode;
  3350. }
  3351.  
  3352.  
  3353. WebInspector.StyleSheetOutlineDialog.show = function(view, uiSourceCode)
  3354. {
  3355. if (WebInspector.Dialog.currentInstance())
  3356. return null;
  3357. var delegate = new WebInspector.StyleSheetOutlineDialog(view, uiSourceCode);
  3358. var filteredItemSelectionDialog = new WebInspector.FilteredItemSelectionDialog(delegate);
  3359. WebInspector.Dialog.show(view.element, filteredItemSelectionDialog);
  3360. }
  3361.  
  3362. WebInspector.StyleSheetOutlineDialog.prototype = {
  3363.  
  3364. itemTitleAt: function(itemIndex)
  3365. {
  3366. return this._rules[itemIndex].selectorText;
  3367. },
  3368.  
  3369.  
  3370. itemSuffixAt: function(itemIndex)
  3371. {
  3372. return "";
  3373. },
  3374.  
  3375.  
  3376. itemSubtitleAt: function(itemIndex)
  3377. {
  3378. return ":" + (this._rules[itemIndex].sourceLine + 1);
  3379. },
  3380.  
  3381.  
  3382. itemKeyAt: function(itemIndex)
  3383. {
  3384. return this._rules[itemIndex].selectorText;
  3385. },
  3386.  
  3387.  
  3388. itemsCount: function()
  3389. {
  3390. return this._rules.length;
  3391. },
  3392.  
  3393.  
  3394. requestItems: function(callback)
  3395. {
  3396. function didGetAllStyleSheets(error, infos)
  3397. {
  3398. if (error) {
  3399. callback(0, 0, 0, 0);
  3400. return;
  3401. }
  3402.  
  3403. for (var i = 0; i < infos.length; ++i) {
  3404. var info = infos[i];
  3405. if (info.sourceURL === this._uiSourceCode.contentURL()) {
  3406. WebInspector.CSSStyleSheet.createForId(info.styleSheetId, didGetStyleSheet.bind(this));
  3407. return;
  3408. }
  3409. }
  3410. callback(0, 0, 0, 0);
  3411. }
  3412.  
  3413. CSSAgent.getAllStyleSheets(didGetAllStyleSheets.bind(this));
  3414.  
  3415.  
  3416. function didGetStyleSheet(styleSheet)
  3417. {
  3418. if (!styleSheet) {
  3419. callback(0, 0, 0, 0);
  3420. return;
  3421. }
  3422.  
  3423. this._rules = styleSheet.rules;
  3424. callback(0, this._rules.length, 0, 1);
  3425. }
  3426. },
  3427.  
  3428.  
  3429. selectItem: function(itemIndex, promptValue)
  3430. {
  3431. var lineNumber = this._rules[itemIndex].sourceLine;
  3432. if (!isNaN(lineNumber) && lineNumber >= 0)
  3433. this._view.highlightLine(lineNumber);
  3434. this._view.focus();
  3435. },
  3436.  
  3437.  
  3438. rewriteQuery: function(query)
  3439. {
  3440. return query;
  3441. },
  3442.  
  3443. __proto__: WebInspector.SelectionDialogContentProvider.prototype
  3444. }
  3445. ;
  3446.  
  3447.  
  3448.  
  3449. WebInspector.TabbedEditorContainerDelegate = function() { }
  3450.  
  3451. WebInspector.TabbedEditorContainerDelegate.prototype = {
  3452.  
  3453. viewForFile: function(uiSourceCode) { }
  3454. }
  3455.  
  3456.  
  3457. WebInspector.TabbedEditorContainer = function(delegate, settingName)
  3458. {
  3459. WebInspector.Object.call(this);
  3460. this._delegate = delegate;
  3461.  
  3462. this._tabbedPane = new WebInspector.TabbedPane();
  3463. this._tabbedPane.closeableTabs = true;
  3464. this._tabbedPane.element.id = "scripts-editor-container-tabbed-pane";
  3465.  
  3466. this._tabbedPane.addEventListener(WebInspector.TabbedPane.EventTypes.TabClosed, this._tabClosed, this);
  3467. this._tabbedPane.addEventListener(WebInspector.TabbedPane.EventTypes.TabSelected, this._tabSelected, this);
  3468.  
  3469. this._tabIds = new Map();
  3470. this._files = {};
  3471. this._loadedURLs = {};
  3472.  
  3473. this._previouslyViewedFilesSetting = WebInspector.settings.createSetting(settingName, []);
  3474. this._history = WebInspector.TabbedEditorContainer.History.fromObject(this._previouslyViewedFilesSetting.get());
  3475. }
  3476.  
  3477.  
  3478. WebInspector.TabbedEditorContainer.Events = {
  3479. EditorSelected: "EditorSelected",
  3480. EditorClosed: "EditorClosed"
  3481. }
  3482.  
  3483. WebInspector.TabbedEditorContainer._tabId = 0;
  3484.  
  3485. WebInspector.TabbedEditorContainer.maximalPreviouslyViewedFilesCount = 30;
  3486.  
  3487. WebInspector.TabbedEditorContainer.prototype = {
  3488.  
  3489. get view()
  3490. {
  3491. return this._tabbedPane;
  3492. },
  3493.  
  3494.  
  3495. get visibleView()
  3496. {
  3497. return this._tabbedPane.visibleView;
  3498. },
  3499.  
  3500.  
  3501. show: function(parentElement)
  3502. {
  3503. this._tabbedPane.show(parentElement);
  3504. },
  3505.  
  3506.  
  3507. showFile: function(uiSourceCode)
  3508. {
  3509. this._innerShowFile(uiSourceCode, true);
  3510. },
  3511.  
  3512. _addScrollAndSelectionListeners: function()
  3513. {
  3514. console.assert(this._currentFile);
  3515. var sourceFrame = this._delegate.viewForFile(this._currentFile);
  3516. sourceFrame.addEventListener(WebInspector.SourceFrame.Events.ScrollChanged, this._scrollChanged, this);
  3517. sourceFrame.addEventListener(WebInspector.SourceFrame.Events.SelectionChanged, this._selectionChanged, this);
  3518. },
  3519.  
  3520. _removeScrollAndSelectionListeners: function()
  3521. {
  3522. if (!this._currentFile)
  3523. return;
  3524. var sourceFrame = this._delegate.viewForFile(this._currentFile);
  3525. sourceFrame.removeEventListener(WebInspector.SourceFrame.Events.ScrollChanged, this._scrollChanged, this);
  3526. sourceFrame.removeEventListener(WebInspector.SourceFrame.Events.SelectionChanged, this._selectionChanged, this);
  3527. },
  3528.  
  3529. _scrollChanged: function(event)
  3530. {
  3531. var lineNumber =   (event.data);
  3532. this._history.updateScrollLineNumber(this._currentFile.url, lineNumber);
  3533. this._history.save(this._previouslyViewedFilesSetting);
  3534. },
  3535.  
  3536. _selectionChanged: function(event)
  3537. {
  3538. var range =   (event.data);
  3539. this._history.updateSelectionRange(this._currentFile.url, range);
  3540. this._history.save(this._previouslyViewedFilesSetting);
  3541. },
  3542.  
  3543.  
  3544. _innerShowFile: function(uiSourceCode, userGesture)
  3545. {
  3546. if (this._currentFile === uiSourceCode)
  3547. return;
  3548. this._removeScrollAndSelectionListeners();
  3549. this._currentFile = uiSourceCode;
  3550.  
  3551. var tabId = this._tabIds.get(uiSourceCode) || this._appendFileTab(uiSourceCode, userGesture);
  3552.  
  3553. this._tabbedPane.selectTab(tabId, userGesture);
  3554. if (userGesture)
  3555. this._editorSelectedByUserAction();
  3556.  
  3557. this._addScrollAndSelectionListeners();
  3558.  
  3559. this.dispatchEventToListeners(WebInspector.TabbedEditorContainer.Events.EditorSelected, this._currentFile);
  3560. },
  3561.  
  3562.  
  3563. _titleForFile: function(uiSourceCode)
  3564. {
  3565. const maxDisplayNameLength = 30;
  3566. const minDisplayQueryParamLength = 5;
  3567.  
  3568. var title;
  3569. var parsedURL = uiSourceCode.parsedURL;
  3570. if (!parsedURL.isValid)
  3571. title = parsedURL.url ? parsedURL.url.trimMiddle(maxDisplayNameLength) : WebInspector.UIString("(program)");
  3572. else {
  3573. var maxDisplayQueryParamLength = Math.max(minDisplayQueryParamLength, maxDisplayNameLength - parsedURL.lastPathComponent.length);
  3574. var displayQueryParams = parsedURL.queryParams ? "?" + parsedURL.queryParams.trimEnd(maxDisplayQueryParamLength - 1) : "";
  3575. var displayLastPathComponent = parsedURL.lastPathComponent.trimMiddle(maxDisplayNameLength - displayQueryParams.length);
  3576. var displayName = displayLastPathComponent + displayQueryParams;
  3577. title = displayName || WebInspector.UIString("(program)");
  3578. }
  3579.  
  3580. if (uiSourceCode.isDirty())
  3581. title += "*";
  3582. return title;
  3583. },
  3584.  
  3585.  
  3586. addUISourceCode: function(uiSourceCode)
  3587. {
  3588. if (this._userSelectedFiles || this._loadedURLs[uiSourceCode.url])
  3589. return;
  3590. this._loadedURLs[uiSourceCode.url] = true;
  3591.  
  3592. var index = this._history.index(uiSourceCode.url)
  3593. if (index === -1)
  3594. return;
  3595.  
  3596. var tabId = this._tabIds.get(uiSourceCode) || this._appendFileTab(uiSourceCode, false);
  3597.  
  3598.  
  3599. if (index === 0)
  3600. this._innerShowFile(uiSourceCode, false);
  3601. },
  3602.  
  3603.  
  3604. removeUISourceCode: function(uiSourceCode)
  3605. {
  3606. var wasCurrent = this._currentFile === uiSourceCode;
  3607.  
  3608. var tabId = this._tabIds.get(uiSourceCode);
  3609. if (tabId)
  3610. this._tabbedPane.closeTab(tabId);
  3611.  
  3612. if (wasCurrent && uiSourceCode.isTemporary) {
  3613. var newUISourceCode = WebInspector.workspace.uiSourceCodeForURL(uiSourceCode.url);
  3614. if (newUISourceCode)
  3615. this._innerShowFile(newUISourceCode, false);
  3616. }
  3617. },
  3618.  
  3619.  
  3620. _editorClosedByUserAction: function(uiSourceCode)
  3621. {
  3622. this._userSelectedFiles = true;
  3623. this._history.remove(uiSourceCode.url);
  3624. this._updateHistory();
  3625. },
  3626.  
  3627. _editorSelectedByUserAction: function()
  3628. {
  3629. this._userSelectedFiles = true;
  3630. this._updateHistory();
  3631. },
  3632.  
  3633. _updateHistory: function()
  3634. {
  3635. var tabIds = this._tabbedPane.lastOpenedTabIds(WebInspector.TabbedEditorContainer.maximalPreviouslyViewedFilesCount);
  3636.  
  3637. function tabIdToURL(tabId)
  3638. {
  3639. return this._files[tabId].url;
  3640. }
  3641.  
  3642. this._history.update(tabIds.map(tabIdToURL.bind(this)));
  3643. this._history.save(this._previouslyViewedFilesSetting);
  3644. },
  3645.  
  3646.  
  3647. _tooltipForFile: function(uiSourceCode)
  3648. {
  3649. return uiSourceCode.url;
  3650. },
  3651.  
  3652.  
  3653. _appendFileTab: function(uiSourceCode, userGesture)
  3654. {
  3655. var view = this._delegate.viewForFile(uiSourceCode);
  3656. var title = this._titleForFile(uiSourceCode);
  3657. var tooltip = this._tooltipForFile(uiSourceCode);
  3658.  
  3659. var tabId = this._generateTabId();
  3660. this._tabIds.put(uiSourceCode, tabId);
  3661. this._files[tabId] = uiSourceCode;
  3662.  
  3663. var savedScrollLineNumber = this._history.scrollLineNumber(uiSourceCode.url);
  3664. if (savedScrollLineNumber)
  3665. view.scrollToLine(savedScrollLineNumber);
  3666. var savedSelectionRange = this._history.selectionRange(uiSourceCode.url);
  3667. if (savedSelectionRange)
  3668. view.setSelection(savedSelectionRange);
  3669.  
  3670. this._tabbedPane.appendTab(tabId, title, view, tooltip, userGesture);
  3671.  
  3672. this._addUISourceCodeListeners(uiSourceCode);
  3673. return tabId;
  3674. },
  3675.  
  3676.  
  3677. _tabClosed: function(event)
  3678. {
  3679. var tabId =   (event.data.tabId);
  3680. var userGesture =   (event.data.isUserGesture);
  3681.  
  3682. var uiSourceCode = this._files[tabId];
  3683. if (this._currentFile === uiSourceCode) {
  3684. this._removeScrollAndSelectionListeners();
  3685. delete this._currentFile;
  3686. }
  3687. this._tabIds.remove(uiSourceCode);
  3688. delete this._files[tabId];
  3689.  
  3690. this._removeUISourceCodeListeners(uiSourceCode);
  3691.  
  3692. this.dispatchEventToListeners(WebInspector.TabbedEditorContainer.Events.EditorClosed, uiSourceCode);
  3693.  
  3694. if (userGesture)
  3695. this._editorClosedByUserAction(uiSourceCode);
  3696. },
  3697.  
  3698.  
  3699. _tabSelected: function(event)
  3700. {
  3701. var tabId =   (event.data.tabId);
  3702. var userGesture =   (event.data.isUserGesture);
  3703.  
  3704. var uiSourceCode = this._files[tabId];
  3705. this._innerShowFile(uiSourceCode, userGesture);
  3706. },
  3707.  
  3708.  
  3709. _addUISourceCodeListeners: function(uiSourceCode)
  3710. {
  3711. uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.TitleChanged, this._uiSourceCodeTitleChanged, this);
  3712. uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyChanged, this._uiSourceCodeWorkingCopyChanged, this);
  3713. uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._uiSourceCodeWorkingCopyCommitted, this);
  3714. uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.FormattedChanged, this._uiSourceCodeFormattedChanged, this);
  3715. },
  3716.  
  3717.  
  3718. _removeUISourceCodeListeners: function(uiSourceCode)
  3719. {
  3720. uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.TitleChanged, this._uiSourceCodeTitleChanged, this);
  3721. uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.WorkingCopyChanged, this._uiSourceCodeWorkingCopyChanged, this);
  3722. uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._uiSourceCodeWorkingCopyCommitted, this);
  3723. uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events.FormattedChanged, this._uiSourceCodeFormattedChanged, this);
  3724. },
  3725.  
  3726.  
  3727. _updateFileTitle: function(uiSourceCode)
  3728. {
  3729. var tabId = this._tabIds.get(uiSourceCode);
  3730. if (tabId) {
  3731. var title = this._titleForFile(uiSourceCode);
  3732. this._tabbedPane.changeTabTitle(tabId, title);
  3733. }
  3734. },
  3735.  
  3736. _uiSourceCodeTitleChanged: function(event)
  3737. {
  3738. var uiSourceCode =   (event.target);
  3739. this._updateFileTitle(uiSourceCode);
  3740. },
  3741.  
  3742. _uiSourceCodeWorkingCopyChanged: function(event)
  3743. {
  3744. var uiSourceCode =   (event.target);
  3745. this._updateFileTitle(uiSourceCode);
  3746. },
  3747.  
  3748. _uiSourceCodeWorkingCopyCommitted: function(event)
  3749. {
  3750. var uiSourceCode =   (event.target);
  3751. this._updateFileTitle(uiSourceCode);
  3752. },
  3753.  
  3754. _uiSourceCodeFormattedChanged: function(event)
  3755. {
  3756. var uiSourceCode =   (event.target);
  3757. this._updateFileTitle(uiSourceCode);
  3758. },
  3759.  
  3760. reset: function()
  3761. {
  3762. this._tabbedPane.closeAllTabs();
  3763. this._tabIds = new Map();
  3764. this._files = {};
  3765. delete this._currentFile;
  3766. delete this._userSelectedFiles;
  3767. this._loadedURLs = {};
  3768. },
  3769.  
  3770.  
  3771. _generateTabId: function()
  3772. {
  3773. return "tab_" + (WebInspector.TabbedEditorContainer._tabId++);
  3774. },
  3775.  
  3776.  
  3777. currentFile: function()
  3778. {
  3779. return this._currentFile;
  3780. },
  3781.  
  3782. __proto__: WebInspector.Object.prototype
  3783. }
  3784.  
  3785.  
  3786. WebInspector.TabbedEditorContainer.HistoryItem = function(url, selectionRange, scrollLineNumber)
  3787. {
  3788. this.url = url;
  3789. this.selectionRange = selectionRange;
  3790. this.scrollLineNumber = scrollLineNumber;
  3791. }
  3792.  
  3793.  
  3794. WebInspector.TabbedEditorContainer.HistoryItem.fromObject = function (serializedHistoryItem)
  3795. {
  3796. var selectionRange = serializedHistoryItem.selectionRange ? WebInspector.TextRange.fromObject(serializedHistoryItem.selectionRange) : null;
  3797. return new WebInspector.TabbedEditorContainer.HistoryItem(serializedHistoryItem.url, selectionRange, serializedHistoryItem.scrollLineNumber);
  3798. }
  3799.  
  3800. WebInspector.TabbedEditorContainer.HistoryItem.prototype = {
  3801.  
  3802. serializeToObject: function()
  3803. {
  3804. var serializedHistoryItem = {};
  3805. serializedHistoryItem.url = this.url;
  3806. serializedHistoryItem.selectionRange = this.selectionRange;
  3807. serializedHistoryItem.scrollLineNumber = this.scrollLineNumber;
  3808. return serializedHistoryItem;
  3809. },
  3810.  
  3811. __proto__: WebInspector.Object.prototype
  3812. }
  3813.  
  3814.  
  3815. WebInspector.TabbedEditorContainer.History = function(items)
  3816. {
  3817. this._items = items;
  3818. }
  3819.  
  3820.  
  3821. WebInspector.TabbedEditorContainer.History.fromObject = function(serializedHistory)
  3822. {
  3823. var items = [];
  3824. for (var i = 0; i < serializedHistory.length; ++i)
  3825. items.push(WebInspector.TabbedEditorContainer.HistoryItem.fromObject(serializedHistory[i]));
  3826. return new WebInspector.TabbedEditorContainer.History(items);
  3827. }
  3828.  
  3829. WebInspector.TabbedEditorContainer.History.prototype = {
  3830.  
  3831. index: function(url)
  3832. {
  3833. for (var i = 0; i < this._items.length; ++i) {
  3834. if (this._items[i].url === url)
  3835. return i;
  3836. }
  3837. return -1;
  3838. },
  3839.  
  3840.  
  3841. selectionRange: function(url)
  3842. {
  3843. var index = this.index(url);
  3844. return index !== -1 ? this._items[index].selectionRange : undefined;
  3845. },
  3846.  
  3847.  
  3848. updateSelectionRange: function(url, selectionRange)
  3849. {
  3850. if (!selectionRange)
  3851. return;
  3852. var index = this.index(url);
  3853. if (index === -1)
  3854. return;
  3855. this._items[index].selectionRange = selectionRange;
  3856. },
  3857.  
  3858.  
  3859. scrollLineNumber: function(url)
  3860. {
  3861. var index = this.index(url);
  3862. return index !== -1 ? this._items[index].scrollLineNumber : undefined;
  3863. },
  3864.  
  3865.  
  3866. updateScrollLineNumber: function(url, scrollLineNumber)
  3867. {
  3868. var index = this.index(url);
  3869. if (index === -1)
  3870. return;
  3871. this._items[index].scrollLineNumber = scrollLineNumber;
  3872. },
  3873.  
  3874.  
  3875. update: function(urls)
  3876. {
  3877. for (var i = urls.length - 1; i >= 0; --i) {
  3878. var index = this.index(urls[i]);
  3879. var item;
  3880. if (index !== -1) {
  3881. item = this._items[index];
  3882. this._items.splice(index, 1);
  3883. } else
  3884. item = new WebInspector.TabbedEditorContainer.HistoryItem(urls[i]);
  3885. this._items.unshift(item);
  3886. }
  3887. },
  3888.  
  3889.  
  3890. remove: function(url)
  3891. {
  3892. var index = this.index(url);
  3893. if (index !== -1)
  3894. this._items.splice(index, 1);
  3895. },
  3896.  
  3897.  
  3898. save: function(setting)
  3899. {
  3900. setting.set(this._serializeToObject());
  3901. },
  3902.  
  3903.  
  3904. _serializeToObject: function()
  3905. {
  3906. var serializedHistory = [];
  3907. for (var i = 0; i < this._items.length; ++i)
  3908. serializedHistory.push(this._items[i].serializeToObject());
  3909. return serializedHistory;
  3910. },
  3911.  
  3912. __proto__: WebInspector.Object.prototype
  3913. }
  3914. ;
  3915.  
  3916.  
  3917.  
  3918. WebInspector.UISourceCodeFrame = function(uiSourceCode)
  3919. {
  3920. this._uiSourceCode = uiSourceCode;
  3921. WebInspector.SourceFrame.call(this, this._uiSourceCode);
  3922. this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.FormattedChanged, this._onFormattedChanged, this);
  3923. this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyChanged, this._onWorkingCopyChanged, this);
  3924. this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._onWorkingCopyCommitted, this);
  3925. }
  3926.  
  3927. WebInspector.UISourceCodeFrame.prototype = {
  3928.  
  3929. canEditSource: function()
  3930. {
  3931. return true;
  3932. },
  3933.  
  3934.  
  3935. commitEditing: function(text)
  3936. {
  3937. if (!this._uiSourceCode.isDirty())
  3938. return;
  3939.  
  3940. this._isCommittingEditing = true;
  3941. this._uiSourceCode.commitWorkingCopy(this._didEditContent.bind(this));
  3942. delete this._isCommittingEditing;
  3943. },
  3944.  
  3945. onTextChanged: function(oldRange, newRange)
  3946. {
  3947. this._isSettingWorkingCopy = true;
  3948. this._uiSourceCode.setWorkingCopy(this._textEditor.text());
  3949. delete this._isSettingWorkingCopy;
  3950. },
  3951.  
  3952. _didEditContent: function(error)
  3953. {
  3954. if (error) {
  3955. WebInspector.log(error, WebInspector.ConsoleMessage.MessageLevel.Error, true);
  3956. return;
  3957. }
  3958. },
  3959.  
  3960.  
  3961. _onFormattedChanged: function(event)
  3962. {
  3963. var content =   (event.data.content);
  3964. this._textEditor.setReadOnly(this._uiSourceCode.formatted());
  3965. this._innerSetContent(content);
  3966. },
  3967.  
  3968.  
  3969. _onWorkingCopyChanged: function(event)
  3970. {
  3971. this._innerSetContent(this._uiSourceCode.workingCopy());
  3972. },
  3973.  
  3974.  
  3975. _onWorkingCopyCommitted: function(event)
  3976. {
  3977. this._innerSetContent(this._uiSourceCode.workingCopy());
  3978. },
  3979.  
  3980. _innerSetContent: function(content)
  3981. {
  3982. if (this._isSettingWorkingCopy || this._isCommittingEditing)
  3983. return;
  3984.  
  3985. this.setContent(this._uiSourceCode.content() || "", false, this._uiSourceCode.contentType().canonicalMimeType());
  3986. },
  3987.  
  3988. populateTextAreaContextMenu: function(contextMenu, lineNumber)
  3989. {
  3990. WebInspector.SourceFrame.prototype.populateTextAreaContextMenu.call(this, contextMenu, lineNumber);
  3991. contextMenu.appendApplicableItems(this._uiSourceCode);
  3992. contextMenu.appendSeparator();
  3993. },
  3994.  
  3995. __proto__: WebInspector.SourceFrame.prototype
  3996. }
  3997. ;
  3998.  
  3999.  
  4000.  
  4001. WebInspector.WatchExpressionsSidebarPane = function()
  4002. {
  4003. WebInspector.SidebarPane.call(this, WebInspector.UIString("Watch Expressions"));
  4004. }
  4005.  
  4006. WebInspector.WatchExpressionsSidebarPane.prototype = {
  4007. show: function()
  4008. {
  4009. this._visible = true;
  4010.  
  4011.  
  4012. if (this._wasShown) {
  4013. this._refreshExpressionsIfNeeded();
  4014. return;
  4015. }
  4016.  
  4017. this._wasShown = true;
  4018.  
  4019. this.section = new WebInspector.WatchExpressionsSection();
  4020. this.bodyElement.appendChild(this.section.element);
  4021.  
  4022. var refreshButton = document.createElement("button");
  4023. refreshButton.className = "pane-title-button refresh";
  4024. refreshButton.addEventListener("click", this._refreshButtonClicked.bind(this), false);
  4025. refreshButton.title = WebInspector.UIString("Refresh");
  4026. this.titleElement.appendChild(refreshButton);
  4027.  
  4028. var addButton = document.createElement("button");
  4029. addButton.className = "pane-title-button add";
  4030. addButton.addEventListener("click", this._addButtonClicked.bind(this), false);
  4031. this.titleElement.appendChild(addButton);
  4032. addButton.title = WebInspector.UIString("Add watch expression");
  4033. this._requiresUpdate = true;
  4034.  
  4035. if (WebInspector.settings.watchExpressions.get().length > 0)
  4036. this.expanded = true;
  4037. },
  4038.  
  4039. hide: function()
  4040. {
  4041. this._visible = false;
  4042. },
  4043.  
  4044. reset: function()
  4045. {
  4046. this.refreshExpressions();
  4047. },
  4048.  
  4049. refreshExpressions: function()
  4050. {
  4051. this._requiresUpdate = true;
  4052. this._refreshExpressionsIfNeeded();
  4053. },
  4054.  
  4055. addExpression: function(expression)
  4056. {
  4057. this.section.addExpression(expression);
  4058. this.expanded = true;
  4059. },
  4060.  
  4061. _refreshExpressionsIfNeeded: function()
  4062. {
  4063. if (this._requiresUpdate && this._visible) {
  4064. this.section.update();
  4065. delete this._requiresUpdate;
  4066. } else
  4067. this._requiresUpdate = true;
  4068. },
  4069.  
  4070. _addButtonClicked: function(event)
  4071. {
  4072. event.consume();
  4073. this.expanded = true;
  4074. this.section.addNewExpressionAndEdit();
  4075. },
  4076.  
  4077. _refreshButtonClicked: function(event)
  4078. {
  4079. event.consume();
  4080. this.refreshExpressions();
  4081. },
  4082.  
  4083. __proto__: WebInspector.SidebarPane.prototype
  4084. }
  4085.  
  4086.  
  4087. WebInspector.WatchExpressionsSection = function()
  4088. {
  4089. this._watchObjectGroupId = "watch-group";
  4090.  
  4091. WebInspector.ObjectPropertiesSection.call(this, WebInspector.RemoteObject.fromPrimitiveValue(""));
  4092.  
  4093. this.treeElementConstructor = WebInspector.WatchedPropertyTreeElement;
  4094. this._expandedExpressions = {};
  4095. this._expandedProperties = {};
  4096.  
  4097. this.emptyElement = document.createElement("div");
  4098. this.emptyElement.className = "info";
  4099. this.emptyElement.textContent = WebInspector.UIString("No Watch Expressions");
  4100.  
  4101. this.watchExpressions = WebInspector.settings.watchExpressions.get();
  4102.  
  4103. this.headerElement.className = "hidden";
  4104. this.editable = true;
  4105. this.expanded = true;
  4106. this.propertiesElement.addStyleClass("watch-expressions");
  4107.  
  4108. this.element.addEventListener("mousemove", this._mouseMove.bind(this), true);
  4109. this.element.addEventListener("mouseout", this._mouseOut.bind(this), true);
  4110. this.element.addEventListener("dblclick", this._sectionDoubleClick.bind(this), false);
  4111. this.emptyElement.addEventListener("contextmenu", this._emptyElementContextMenu.bind(this), false);
  4112. }
  4113.  
  4114. WebInspector.WatchExpressionsSection.NewWatchExpression = "\xA0";
  4115.  
  4116. WebInspector.WatchExpressionsSection.prototype = {
  4117. update: function(e)
  4118. {
  4119. if (e)
  4120. e.consume();
  4121.  
  4122. function appendResult(expression, watchIndex, result, wasThrown)
  4123. {
  4124. if (!result)
  4125. return;
  4126.  
  4127. var property = new WebInspector.RemoteObjectProperty(expression, result);
  4128. property.watchIndex = watchIndex;
  4129. property.wasThrown = wasThrown;
  4130.  
  4131.  
  4132.  
  4133.  
  4134.  
  4135.  
  4136.  
  4137.  
  4138. properties.push(property);
  4139.  
  4140. if (properties.length == propertyCount) {
  4141. this.updateProperties(properties, WebInspector.WatchExpressionTreeElement, WebInspector.WatchExpressionsSection.CompareProperties);
  4142.  
  4143.  
  4144.  
  4145. if (this._newExpressionAdded) {
  4146. delete this._newExpressionAdded;
  4147.  
  4148. var treeElement = this.findAddedTreeElement();
  4149. if (treeElement)
  4150. treeElement.startEditing();
  4151. }
  4152.  
  4153.  
  4154. if (this._lastMouseMovePageY)
  4155. this._updateHoveredElement(this._lastMouseMovePageY);
  4156. }
  4157. }
  4158.  
  4159.  
  4160. RuntimeAgent.releaseObjectGroup(this._watchObjectGroupId)
  4161. var properties = [];
  4162.  
  4163.  
  4164.  
  4165. var propertyCount = 0;
  4166. for (var i = 0; i < this.watchExpressions.length; ++i) {
  4167. if (!this.watchExpressions[i])
  4168. continue;
  4169. ++propertyCount;
  4170. }
  4171.  
  4172.  
  4173.  
  4174. for (var i = 0; i < this.watchExpressions.length; ++i) {
  4175. var expression = this.watchExpressions[i];
  4176. if (!expression)
  4177. continue;
  4178.  
  4179. WebInspector.runtimeModel.evaluate(expression, this._watchObjectGroupId, false, true, false, false, appendResult.bind(this, expression, i));
  4180. }
  4181.  
  4182. if (!propertyCount) {
  4183. if (!this.emptyElement.parentNode)
  4184. this.element.appendChild(this.emptyElement);
  4185. } else {
  4186. if (this.emptyElement.parentNode)
  4187. this.element.removeChild(this.emptyElement);
  4188. }
  4189.  
  4190.  
  4191.  
  4192.  
  4193. this.expanded = (propertyCount != 0);
  4194. },
  4195.  
  4196. addExpression: function(expression)
  4197. {
  4198. this.watchExpressions.push(expression);
  4199. this.saveExpressions();
  4200. this.update();
  4201. },
  4202.  
  4203. addNewExpressionAndEdit: function()
  4204. {
  4205. this._newExpressionAdded = true;
  4206. this.watchExpressions.push(WebInspector.WatchExpressionsSection.NewWatchExpression);
  4207. this.update();
  4208. },
  4209.  
  4210. _sectionDoubleClick: function(event)
  4211. {
  4212. if (event.target !== this.element && event.target !== this.propertiesElement && event.target !== this.emptyElement)
  4213. return;
  4214. event.consume();
  4215. this.addNewExpressionAndEdit();
  4216. },
  4217.  
  4218. updateExpression: function(element, value)
  4219. {
  4220. if (value === null) {
  4221. var index = element.property.watchIndex;
  4222. this.watchExpressions.splice(index, 1);
  4223. }
  4224. else
  4225. this.watchExpressions[element.property.watchIndex] = value;
  4226. this.saveExpressions();
  4227. this.update();
  4228. },
  4229.  
  4230. _deleteAllExpressions: function()
  4231. {
  4232. this.watchExpressions = [];
  4233. this.saveExpressions();
  4234. this.update();
  4235. },
  4236.  
  4237. findAddedTreeElement: function()
  4238. {
  4239. var children = this.propertiesTreeOutline.children;
  4240. for (var i = 0; i < children.length; ++i) {
  4241. if (children[i].property.name === WebInspector.WatchExpressionsSection.NewWatchExpression)
  4242. return children[i];
  4243. }
  4244. },
  4245.  
  4246. saveExpressions: function()
  4247. {
  4248. var toSave = [];
  4249. for (var i = 0; i < this.watchExpressions.length; i++)
  4250. if (this.watchExpressions[i])
  4251. toSave.push(this.watchExpressions[i]);
  4252.  
  4253. WebInspector.settings.watchExpressions.set(toSave);
  4254. return toSave.length;
  4255. },
  4256.  
  4257. _mouseMove: function(e)
  4258. {
  4259. if (this.propertiesElement.firstChild)
  4260. this._updateHoveredElement(e.pageY);
  4261. },
  4262.  
  4263. _mouseOut: function()
  4264. {
  4265. if (this._hoveredElement) {
  4266. this._hoveredElement.removeStyleClass("hovered");
  4267. delete this._hoveredElement;
  4268. }
  4269. delete this._lastMouseMovePageY;
  4270. },
  4271.  
  4272. _updateHoveredElement: function(pageY)
  4273. {
  4274. var candidateElement = this.propertiesElement.firstChild;
  4275. while (true) {
  4276. var next = candidateElement.nextSibling;
  4277. while (next && !next.clientHeight)
  4278. next = next.nextSibling;
  4279. if (!next || next.totalOffsetTop() > pageY)
  4280. break;
  4281. candidateElement = next;
  4282. }
  4283.  
  4284. if (this._hoveredElement !== candidateElement) {
  4285. if (this._hoveredElement)
  4286. this._hoveredElement.removeStyleClass("hovered");
  4287. if (candidateElement)
  4288. candidateElement.addStyleClass("hovered");
  4289. this._hoveredElement = candidateElement;
  4290. }
  4291.  
  4292. this._lastMouseMovePageY = pageY;
  4293. },
  4294.  
  4295. _emptyElementContextMenu: function(event)
  4296. {
  4297. var contextMenu = new WebInspector.ContextMenu(event);
  4298. contextMenu.appendItem(WebInspector.UIString("Add watch expression"), this.addNewExpressionAndEdit.bind(this));
  4299. contextMenu.show();
  4300. },
  4301.  
  4302. __proto__: WebInspector.ObjectPropertiesSection.prototype
  4303. }
  4304.  
  4305. WebInspector.WatchExpressionsSection.CompareProperties = function(propertyA, propertyB)
  4306. {
  4307. if (propertyA.watchIndex == propertyB.watchIndex)
  4308. return 0;
  4309. else if (propertyA.watchIndex < propertyB.watchIndex)
  4310. return -1;
  4311. else
  4312. return 1;
  4313. }
  4314.  
  4315.  
  4316. WebInspector.WatchExpressionTreeElement = function(property)
  4317. {
  4318. WebInspector.ObjectPropertyTreeElement.call(this, property);
  4319. }
  4320.  
  4321. WebInspector.WatchExpressionTreeElement.prototype = {
  4322. onexpand: function()
  4323. {
  4324. WebInspector.ObjectPropertyTreeElement.prototype.onexpand.call(this);
  4325. this.treeOutline.section._expandedExpressions[this._expression()] = true;
  4326. },
  4327.  
  4328. oncollapse: function()
  4329. {
  4330. WebInspector.ObjectPropertyTreeElement.prototype.oncollapse.call(this);
  4331. delete this.treeOutline.section._expandedExpressions[this._expression()];
  4332. },
  4333.  
  4334. onattach: function()
  4335. {
  4336. WebInspector.ObjectPropertyTreeElement.prototype.onattach.call(this);
  4337. if (this.treeOutline.section._expandedExpressions[this._expression()])
  4338. this.expanded = true;
  4339. },
  4340.  
  4341. _expression: function()
  4342. {
  4343. return this.property.name;
  4344. },
  4345.  
  4346. update: function()
  4347. {
  4348. WebInspector.ObjectPropertyTreeElement.prototype.update.call(this);
  4349.  
  4350. if (this.property.wasThrown) {
  4351. this.valueElement.textContent = WebInspector.UIString("<not available>");
  4352. this.listItemElement.addStyleClass("dimmed");
  4353. } else
  4354. this.listItemElement.removeStyleClass("dimmed");
  4355.  
  4356. var deleteButton = document.createElement("input");
  4357. deleteButton.type = "button";
  4358. deleteButton.title = WebInspector.UIString("Delete watch expression.");
  4359. deleteButton.addStyleClass("enabled-button");
  4360. deleteButton.addStyleClass("delete-button");
  4361. deleteButton.addEventListener("click", this._deleteButtonClicked.bind(this), false);
  4362. this.listItemElement.addEventListener("contextmenu", this._contextMenu.bind(this), false);
  4363. this.listItemElement.insertBefore(deleteButton, this.listItemElement.firstChild);
  4364. },
  4365.  
  4366.  
  4367. populateContextMenu: function(contextMenu)
  4368. {
  4369. if (!this.isEditing()) {
  4370. contextMenu.appendItem(WebInspector.UIString("Add watch expression"), this.treeOutline.section.addNewExpressionAndEdit.bind(this.treeOutline.section));
  4371. contextMenu.appendItem(WebInspector.UIString("Delete watch expression"), this._deleteButtonClicked.bind(this));
  4372. }
  4373. if (this.treeOutline.section.watchExpressions.length > 1)
  4374. contextMenu.appendItem(WebInspector.UIString("Delete all watch expressions"), this._deleteAllButtonClicked.bind(this));
  4375. },
  4376.  
  4377. _contextMenu: function(event)
  4378. {
  4379. var contextMenu = new WebInspector.ContextMenu(event);
  4380. this.populateContextMenu(contextMenu);
  4381. contextMenu.show();
  4382. },
  4383.  
  4384. _deleteAllButtonClicked: function()
  4385. {
  4386. this.treeOutline.section._deleteAllExpressions();
  4387. },
  4388.  
  4389. _deleteButtonClicked: function()
  4390. {
  4391. this.treeOutline.section.updateExpression(this, null);
  4392. },
  4393.  
  4394. renderPromptAsBlock: function()
  4395. {
  4396. return true;
  4397. },
  4398.  
  4399.  
  4400. elementAndValueToEdit: function(event)
  4401. {
  4402. return [this.nameElement, this.property.name.trim()];
  4403. },
  4404.  
  4405. editingCancelled: function(element, context)
  4406. {
  4407. if (!context.elementToEdit.textContent)
  4408. this.treeOutline.section.updateExpression(this, null);
  4409.  
  4410. WebInspector.ObjectPropertyTreeElement.prototype.editingCancelled.call(this, element, context);
  4411. },
  4412.  
  4413. applyExpression: function(expression, updateInterface)
  4414. {
  4415. expression = expression.trim();
  4416.  
  4417. if (!expression)
  4418. expression = null;
  4419.  
  4420. this.property.name = expression;
  4421. this.treeOutline.section.updateExpression(this, expression);
  4422. },
  4423.  
  4424. __proto__: WebInspector.ObjectPropertyTreeElement.prototype
  4425. }
  4426.  
  4427.  
  4428.  
  4429. WebInspector.WatchedPropertyTreeElement = function(property)
  4430. {
  4431. WebInspector.ObjectPropertyTreeElement.call(this, property);
  4432. }
  4433.  
  4434. WebInspector.WatchedPropertyTreeElement.prototype = {
  4435. onattach: function()
  4436. {
  4437. WebInspector.ObjectPropertyTreeElement.prototype.onattach.call(this);
  4438. if (this.hasChildren && this.propertyPath() in this.treeOutline.section._expandedProperties)
  4439. this.expand();
  4440. },
  4441.  
  4442. onexpand: function()
  4443. {
  4444. WebInspector.ObjectPropertyTreeElement.prototype.onexpand.call(this);
  4445. this.treeOutline.section._expandedProperties[this.propertyPath()] = true;
  4446. },
  4447.  
  4448. oncollapse: function()
  4449. {
  4450. WebInspector.ObjectPropertyTreeElement.prototype.oncollapse.call(this);
  4451. delete this.treeOutline.section._expandedProperties[this.propertyPath()];
  4452. },
  4453.  
  4454. __proto__: WebInspector.ObjectPropertyTreeElement.prototype
  4455. }
  4456. ;
  4457.  
  4458.  
  4459.  
  4460. WebInspector.Worker = function(id, url, shared)
  4461. {
  4462. this.id = id;
  4463. this.url = url;
  4464. this.shared = shared;
  4465. }
  4466.  
  4467.  
  4468. WebInspector.WorkersSidebarPane = function(workerManager)
  4469. {
  4470. WebInspector.SidebarPane.call(this, WebInspector.UIString("Workers"));
  4471.  
  4472. this._enableWorkersCheckbox = new WebInspector.Checkbox(
  4473. WebInspector.UIString("Pause on start"),
  4474. "sidebar-label",
  4475. WebInspector.UIString("Automatically attach to new workers and pause them. Enabling this option will force opening inspector for all new workers."));
  4476. this._enableWorkersCheckbox.element.id = "pause-workers-checkbox";
  4477. this.bodyElement.appendChild(this._enableWorkersCheckbox.element);
  4478. this._enableWorkersCheckbox.addEventListener(this._autoattachToWorkersClicked.bind(this));
  4479. this._enableWorkersCheckbox.checked = false;
  4480.  
  4481. if (Preferences.sharedWorkersDebugNote) {
  4482. var note = this.bodyElement.createChild("div");
  4483. note.id = "shared-workers-list";
  4484. note.addStyleClass("sidebar-label")
  4485. note.textContent = Preferences.sharedWorkersDebugNote;
  4486. }
  4487.  
  4488. var separator = this.bodyElement.createChild("div", "sidebar-separator");
  4489. separator.textContent = WebInspector.UIString("Dedicated worker inspectors");
  4490.  
  4491. this._workerListElement = document.createElement("ol");
  4492. this._workerListElement.tabIndex = 0;
  4493. this._workerListElement.addStyleClass("properties-tree");
  4494. this._workerListElement.addStyleClass("sidebar-label");
  4495. this.bodyElement.appendChild(this._workerListElement);
  4496.  
  4497. this._idToWorkerItem = {};
  4498. this._workerManager = workerManager;
  4499.  
  4500. workerManager.addEventListener(WebInspector.WorkerManager.Events.WorkerAdded, this._workerAdded, this);
  4501. workerManager.addEventListener(WebInspector.WorkerManager.Events.WorkerRemoved, this._workerRemoved, this);
  4502. workerManager.addEventListener(WebInspector.WorkerManager.Events.WorkersCleared, this._workersCleared, this);
  4503. }
  4504.  
  4505. WebInspector.WorkersSidebarPane.prototype = {
  4506. _workerAdded: function(event)
  4507. {
  4508. this._addWorker(event.data.workerId, event.data.url, event.data.inspectorConnected);
  4509. },
  4510.  
  4511. _workerRemoved: function(event)
  4512. {
  4513. var workerItem = this._idToWorkerItem[event.data];
  4514. delete this._idToWorkerItem[event.data];
  4515. workerItem.parentElement.removeChild(workerItem);
  4516. },
  4517.  
  4518. _workersCleared: function(event)
  4519. {
  4520. this._idToWorkerItem = {};
  4521. this._workerListElement.removeChildren();
  4522. },
  4523.  
  4524. _addWorker: function(workerId, url, inspectorConnected)
  4525. {
  4526. var item = this._workerListElement.createChild("div", "dedicated-worker-item");
  4527. var link = item.createChild("a");
  4528. link.textContent = url;
  4529. link.href = "#";
  4530. link.target = "_blank";
  4531. link.addEventListener("click", this._workerItemClicked.bind(this, workerId), true);
  4532. this._idToWorkerItem[workerId] = item;
  4533. },
  4534.  
  4535. _workerItemClicked: function(workerId, event)
  4536. {
  4537. event.preventDefault();
  4538. this._workerManager.openWorkerInspector(workerId);
  4539. },
  4540.  
  4541. _autoattachToWorkersClicked: function(event)
  4542. {
  4543. WorkerAgent.setAutoconnectToWorkers(this._enableWorkersCheckbox.checked);
  4544. },
  4545.  
  4546. __proto__: WebInspector.SidebarPane.prototype
  4547. }
  4548. ;
  4549.  
  4550.  
  4551. WebInspector.ScriptsPanel = function(workspaceForTest)
  4552. {
  4553. WebInspector.Panel.call(this, "scripts");
  4554. this.registerRequiredCSS("scriptsPanel.css");
  4555.  
  4556. WebInspector.settings.navigatorWasOnceHidden = WebInspector.settings.createSetting("navigatorWasOnceHidden", false);
  4557. WebInspector.settings.debuggerSidebarHidden = WebInspector.settings.createSetting("debuggerSidebarHidden", false);
  4558.  
  4559. this._workspace = workspaceForTest || WebInspector.workspace;
  4560.  
  4561. function viewGetter()
  4562. {
  4563. return this.visibleView;
  4564. }
  4565. WebInspector.GoToLineDialog.install(this, viewGetter.bind(this));
  4566.  
  4567. var helpSection = WebInspector.shortcutsScreen.section(WebInspector.UIString("Sources Panel"));
  4568. this.debugToolbar = this._createDebugToolbar();
  4569.  
  4570. const initialDebugSidebarWidth = 225;
  4571. const minimumDebugSidebarWidthPercent = 50;
  4572. this.createSidebarView(this.element, WebInspector.SidebarView.SidebarPosition.Right, initialDebugSidebarWidth);
  4573. this.splitView.element.id = "scripts-split-view";
  4574. this.splitView.setMinimumSidebarWidth(Preferences.minScriptsSidebarWidth);
  4575. this.splitView.setMinimumMainWidthPercent(minimumDebugSidebarWidthPercent);
  4576.  
  4577. this.sidebarElement.appendChild(this.debugToolbar);
  4578.  
  4579. this.debugSidebarResizeWidgetElement = document.createElement("div");
  4580. this.debugSidebarResizeWidgetElement.id = "scripts-debug-sidebar-resizer-widget";
  4581. this.splitView.installResizer(this.debugSidebarResizeWidgetElement);
  4582.  
  4583.  
  4584. const initialNavigatorWidth = 225;
  4585. const minimumViewsContainerWidthPercent = 50;
  4586. this.editorView = new WebInspector.SidebarView(WebInspector.SidebarView.SidebarPosition.Left, "scriptsPanelNavigatorSidebarWidth", initialNavigatorWidth);
  4587. this.editorView.element.tabIndex = 0;
  4588.  
  4589. this.editorView.setMinimumSidebarWidth(Preferences.minScriptsSidebarWidth);
  4590. this.editorView.setMinimumMainWidthPercent(minimumViewsContainerWidthPercent);
  4591. this.editorView.show(this.splitView.mainElement);
  4592.  
  4593. this._navigator = new WebInspector.ScriptsNavigator();
  4594. this._navigator.view.show(this.editorView.sidebarElement);
  4595.  
  4596. this._editorContainer = new WebInspector.TabbedEditorContainer(this, "previouslyViewedFiles");
  4597. this._editorContainer.show(this.editorView.mainElement);
  4598.  
  4599. this._navigatorController = new WebInspector.NavigatorOverlayController(this.editorView, this._navigator.view, this._editorContainer.view);
  4600.  
  4601. this._navigator.addEventListener(WebInspector.ScriptsNavigator.Events.ScriptSelected, this._scriptSelected, this);
  4602. this._navigator.addEventListener(WebInspector.ScriptsNavigator.Events.SnippetCreationRequested, this._snippetCreationRequested, this);
  4603. this._navigator.addEventListener(WebInspector.ScriptsNavigator.Events.ItemRenamingRequested, this._itemRenamingRequested, this);
  4604. this._navigator.addEventListener(WebInspector.ScriptsNavigator.Events.FileRenamed, this._fileRenamed, this);
  4605.  
  4606. this._editorContainer.addEventListener(WebInspector.TabbedEditorContainer.Events.EditorSelected, this._editorSelected, this);
  4607. this._editorContainer.addEventListener(WebInspector.TabbedEditorContainer.Events.EditorClosed, this._editorClosed, this);
  4608.  
  4609. this.splitView.mainElement.appendChild(this.debugSidebarResizeWidgetElement);
  4610.  
  4611. this.sidebarPanes = {};
  4612. this.sidebarPanes.watchExpressions = new WebInspector.WatchExpressionsSidebarPane();
  4613. this.sidebarPanes.callstack = new WebInspector.CallStackSidebarPane();
  4614. this.sidebarPanes.scopechain = new WebInspector.ScopeChainSidebarPane();
  4615. this.sidebarPanes.jsBreakpoints = new WebInspector.JavaScriptBreakpointsSidebarPane(WebInspector.breakpointManager, this._showSourceLine.bind(this));
  4616. this.sidebarPanes.domBreakpoints = WebInspector.domBreakpointsSidebarPane;
  4617. this.sidebarPanes.xhrBreakpoints = new WebInspector.XHRBreakpointsSidebarPane();
  4618. this.sidebarPanes.eventListenerBreakpoints = new WebInspector.EventListenerBreakpointsSidebarPane();
  4619.  
  4620. if (InspectorFrontendHost.canInspectWorkers() && !WebInspector.WorkerManager.isWorkerFrontend()) {
  4621. WorkerAgent.enable();
  4622. this.sidebarPanes.workerList = new WebInspector.WorkersSidebarPane(WebInspector.workerManager);
  4623. }
  4624.  
  4625. this._debugSidebarContentsElement = document.createElement("div");
  4626. this._debugSidebarContentsElement.id = "scripts-debug-sidebar-contents";
  4627. this.sidebarElement.appendChild(this._debugSidebarContentsElement);
  4628.  
  4629. for (var pane in this.sidebarPanes) {
  4630. if (this.sidebarPanes[pane] === this.sidebarPanes.domBreakpoints)
  4631. continue;
  4632. this._debugSidebarContentsElement.appendChild(this.sidebarPanes[pane].element);
  4633. }
  4634.  
  4635. this.sidebarPanes.callstack.expanded = true;
  4636.  
  4637. this.sidebarPanes.scopechain.expanded = true;
  4638. this.sidebarPanes.jsBreakpoints.expanded = true;
  4639.  
  4640. this.sidebarPanes.callstack.registerShortcuts(this.registerShortcuts.bind(this));
  4641. this.registerShortcuts(WebInspector.ScriptsPanelDescriptor.ShortcutKeys.EvaluateSelectionInConsole, this._evaluateSelectionInConsole.bind(this));
  4642. this.registerShortcuts(WebInspector.ScriptsPanelDescriptor.ShortcutKeys.GoToMember, this._showOutlineDialog.bind(this));
  4643. this.registerShortcuts(WebInspector.ScriptsPanelDescriptor.ShortcutKeys.ToggleBreakpoint, this._toggleBreakpoint.bind(this));
  4644.  
  4645. var panelEnablerHeading = WebInspector.UIString("You need to enable debugging before you can use the Scripts panel.");
  4646. var panelEnablerDisclaimer = WebInspector.UIString("Enabling debugging will make scripts run slower.");
  4647. var panelEnablerButton = WebInspector.UIString("Enable Debugging");
  4648.  
  4649. this.panelEnablerView = new WebInspector.PanelEnablerView("scripts", panelEnablerHeading, panelEnablerDisclaimer, panelEnablerButton);
  4650. this.panelEnablerView.addEventListener("enable clicked", this._enableDebugging, this);
  4651.  
  4652. this.enableToggleButton = new WebInspector.StatusBarButton("", "enable-toggle-status-bar-item");
  4653. this.enableToggleButton.addEventListener("click", this._toggleDebugging, this);
  4654. if (!Capabilities.debuggerCausesRecompilation)
  4655. this.enableToggleButton.element.addStyleClass("hidden");
  4656.  
  4657. this._pauseOnExceptionButton = new WebInspector.StatusBarButton("", "scripts-pause-on-exceptions-status-bar-item", 3);
  4658. this._pauseOnExceptionButton.addEventListener("click", this._togglePauseOnExceptions, this);
  4659.  
  4660. this._toggleFormatSourceButton = new WebInspector.StatusBarButton(WebInspector.UIString("Pretty print"), "scripts-toggle-pretty-print-status-bar-item");
  4661. this._toggleFormatSourceButton.toggled = false;
  4662. this._toggleFormatSourceButton.addEventListener("click", this._toggleFormatSource, this);
  4663.  
  4664. this._scriptViewStatusBarItemsContainer = document.createElement("div");
  4665. this._scriptViewStatusBarItemsContainer.style.display = "inline-block";
  4666.  
  4667. this._installDebuggerSidebarController();
  4668.  
  4669. this._sourceFramesByUISourceCode = new Map();
  4670. this._updateDebuggerButtons();
  4671. this._pauseOnExceptionStateChanged();
  4672. if (WebInspector.debuggerModel.isPaused())
  4673. this._debuggerPaused();
  4674.  
  4675. WebInspector.settings.pauseOnExceptionStateString.addChangeListener(this._pauseOnExceptionStateChanged, this);
  4676. WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.DebuggerWasEnabled, this._debuggerWasEnabled, this);
  4677. WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.DebuggerWasDisabled, this._debuggerWasDisabled, this);
  4678. WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.DebuggerPaused, this._debuggerPaused, this);
  4679. WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.DebuggerResumed, this._debuggerResumed, this);
  4680. WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.CallFrameSelected, this._callFrameSelected, this);
  4681. WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.ConsoleCommandEvaluatedInSelectedCallFrame, this._consoleCommandEvaluatedInSelectedCallFrame, this);
  4682. WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.ExecutionLineChanged, this._executionLineChanged, this);
  4683. WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.BreakpointsActiveStateChanged, this._breakpointsActiveStateChanged, this);
  4684.  
  4685. WebInspector.startBatchUpdate();
  4686. var uiSourceCodes = this._workspace.uiSourceCodes();
  4687. for (var i = 0; i < uiSourceCodes.length; ++i)
  4688. this._addUISourceCode(uiSourceCodes[i]);
  4689. WebInspector.endBatchUpdate();
  4690.  
  4691. this._workspace.addEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeAdded, this._uiSourceCodeAdded, this);
  4692. this._workspace.addEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeRemoved, this._uiSourceCodeRemoved, this);
  4693. this._workspace.addEventListener(WebInspector.UISourceCodeProvider.Events.TemporaryUISourceCodeRemoved, this._uiSourceCodeRemoved, this);
  4694. this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectWillReset, this._reset.bind(this), this);
  4695.  
  4696. WebInspector.advancedSearchController.registerSearchScope(new WebInspector.ScriptsSearchScope(this._workspace));
  4697. }
  4698.  
  4699. WebInspector.ScriptsPanel.prototype = {
  4700. get statusBarItems()
  4701. {
  4702. return [this.enableToggleButton.element, this._pauseOnExceptionButton.element, this._toggleFormatSourceButton.element, this._scriptViewStatusBarItemsContainer];
  4703. },
  4704.  
  4705. defaultFocusedElement: function()
  4706. {
  4707. return this._navigator.view.defaultFocusedElement();
  4708. },
  4709.  
  4710. get paused()
  4711. {
  4712. return this._paused;
  4713. },
  4714.  
  4715. wasShown: function()
  4716. {
  4717. WebInspector.Panel.prototype.wasShown.call(this);
  4718. this._debugSidebarContentsElement.insertBefore(this.sidebarPanes.domBreakpoints.element, this.sidebarPanes.xhrBreakpoints.element);
  4719. this.sidebarPanes.watchExpressions.show();
  4720.  
  4721. this._navigatorController.wasShown();
  4722. },
  4723.  
  4724. willHide: function()
  4725. {
  4726. WebInspector.Panel.prototype.willHide.call(this);
  4727. WebInspector.closeViewInDrawer();
  4728. },
  4729.  
  4730.  
  4731. _uiSourceCodeAdded: function(event)
  4732. {
  4733. var uiSourceCode =   (event.data);
  4734. this._addUISourceCode(uiSourceCode);
  4735. },
  4736.  
  4737.  
  4738. _addUISourceCode: function(uiSourceCode)
  4739. {
  4740. if (this._toggleFormatSourceButton.toggled)
  4741. uiSourceCode.setFormatted(true);
  4742.  
  4743. this._navigator.addUISourceCode(uiSourceCode);
  4744. this._editorContainer.addUISourceCode(uiSourceCode);
  4745. },
  4746.  
  4747. _uiSourceCodeRemoved: function(event)
  4748. {
  4749. var uiSourceCode =   (event.data);
  4750. this._editorContainer.removeUISourceCode(uiSourceCode);
  4751. this._navigator.removeUISourceCode(uiSourceCode);
  4752. this._removeSourceFrame(uiSourceCode);
  4753. },
  4754.  
  4755. _consoleCommandEvaluatedInSelectedCallFrame: function(event)
  4756. {
  4757. this.sidebarPanes.scopechain.update(WebInspector.debuggerModel.selectedCallFrame());
  4758. },
  4759.  
  4760. _debuggerPaused: function()
  4761. {
  4762. var details = WebInspector.debuggerModel.debuggerPausedDetails();
  4763.  
  4764. this._paused = true;
  4765. this._waitingToPause = false;
  4766. this._stepping = false;
  4767.  
  4768. this._updateDebuggerButtons();
  4769.  
  4770. WebInspector.inspectorView.setCurrentPanel(this);
  4771. this.sidebarPanes.callstack.update(details.callFrames);
  4772.  
  4773. if (details.reason === WebInspector.DebuggerModel.BreakReason.DOM) {
  4774. this.sidebarPanes.domBreakpoints.highlightBreakpoint(details.auxData);
  4775. function didCreateBreakpointHitStatusMessage(element)
  4776. {
  4777. this.sidebarPanes.callstack.setStatus(element);
  4778. }
  4779. this.sidebarPanes.domBreakpoints.createBreakpointHitStatusMessage(details.auxData, didCreateBreakpointHitStatusMessage.bind(this));
  4780. } else if (details.reason === WebInspector.DebuggerModel.BreakReason.EventListener) {
  4781. var eventName = details.auxData.eventName;
  4782. this.sidebarPanes.eventListenerBreakpoints.highlightBreakpoint(details.auxData.eventName);
  4783. var eventNameForUI = WebInspector.EventListenerBreakpointsSidebarPane.eventNameForUI(eventName);
  4784. this.sidebarPanes.callstack.setStatus(WebInspector.UIString("Paused on a \"%s\" Event Listener.", eventNameForUI));
  4785. } else if (details.reason === WebInspector.DebuggerModel.BreakReason.XHR) {
  4786. this.sidebarPanes.xhrBreakpoints.highlightBreakpoint(details.auxData["breakpointURL"]);
  4787. this.sidebarPanes.callstack.setStatus(WebInspector.UIString("Paused on a XMLHttpRequest."));
  4788. } else if (details.reason === WebInspector.DebuggerModel.BreakReason.Exception)
  4789. this.sidebarPanes.callstack.setStatus(WebInspector.UIString("Paused on exception: '%s'.", details.auxData.description));
  4790. else if (details.reason === WebInspector.DebuggerModel.BreakReason.Assert)
  4791. this.sidebarPanes.callstack.setStatus(WebInspector.UIString("Paused on assertion."));
  4792. else if (details.reason === WebInspector.DebuggerModel.BreakReason.CSPViolation)
  4793. this.sidebarPanes.callstack.setStatus(WebInspector.UIString("Paused on a script blocked due to Content Security Policy directive: \"%s\".", details.auxData["directiveText"]));
  4794. else {
  4795. function didGetUILocation(uiLocation)
  4796. {
  4797. var breakpoint = WebInspector.breakpointManager.findBreakpoint(uiLocation.uiSourceCode, uiLocation.lineNumber);
  4798. if (!breakpoint)
  4799. return;
  4800. this.sidebarPanes.jsBreakpoints.highlightBreakpoint(breakpoint);
  4801. this.sidebarPanes.callstack.setStatus(WebInspector.UIString("Paused on a JavaScript breakpoint."));
  4802. }
  4803. details.callFrames[0].createLiveLocation(didGetUILocation.bind(this));
  4804. }
  4805.  
  4806. this._showDebuggerSidebar();
  4807. this._toggleDebuggerSidebarButton.setEnabled(false);
  4808. window.focus();
  4809. InspectorFrontendHost.bringToFront();
  4810. },
  4811.  
  4812. _debuggerResumed: function()
  4813. {
  4814. this._paused = false;
  4815. this._waitingToPause = false;
  4816. this._stepping = false;
  4817.  
  4818. this._clearInterface();
  4819. this._toggleDebuggerSidebarButton.setEnabled(true);
  4820. },
  4821.  
  4822. _debuggerWasEnabled: function()
  4823. {
  4824. this._updateDebuggerButtons();
  4825. },
  4826.  
  4827. _debuggerWasDisabled: function()
  4828. {
  4829. this._reset();
  4830. },
  4831.  
  4832. _reset: function()
  4833. {
  4834. delete this.currentQuery;
  4835. this.searchCanceled();
  4836.  
  4837. this._debuggerResumed();
  4838.  
  4839. delete this._currentUISourceCode;
  4840. this._navigator.reset();
  4841. this._editorContainer.reset();
  4842. this._updateScriptViewStatusBarItems();
  4843. this.sidebarPanes.jsBreakpoints.reset();
  4844. this.sidebarPanes.watchExpressions.reset();
  4845.  
  4846. var uiSourceCodes = this._workspace.uiSourceCodes();
  4847. for (var i = 0; i < uiSourceCodes.length; ++i)
  4848. this._removeSourceFrame(uiSourceCodes[i]);
  4849. },
  4850.  
  4851. get visibleView()
  4852. {
  4853. return this._editorContainer.visibleView;
  4854. },
  4855.  
  4856. _updateScriptViewStatusBarItems: function()
  4857. {
  4858. this._scriptViewStatusBarItemsContainer.removeChildren();
  4859.  
  4860. var sourceFrame = this.visibleView;
  4861. if (sourceFrame) {
  4862. var statusBarItems = sourceFrame.statusBarItems() || [];
  4863. for (var i = 0; i < statusBarItems.length; ++i)
  4864. this._scriptViewStatusBarItemsContainer.appendChild(statusBarItems[i]);
  4865. }
  4866. },
  4867.  
  4868. canShowAnchorLocation: function(anchor)
  4869. {
  4870. if (WebInspector.debuggerModel.debuggerEnabled() && anchor.uiSourceCode)
  4871. return true;
  4872. var uiSourceCodes = this._workspace.uiSourceCodes();
  4873. for (var i = 0; i < uiSourceCodes.length; ++i) {
  4874. if (uiSourceCodes[i].url === anchor.href) {
  4875. anchor.uiSourceCode = uiSourceCodes[i];
  4876. return true;
  4877. }
  4878. }
  4879. return false;
  4880. },
  4881.  
  4882. showAnchorLocation: function(anchor)
  4883. {
  4884. this._showSourceLine(anchor.uiSourceCode, anchor.lineNumber);
  4885. },
  4886.  
  4887.  
  4888. showUISourceCode: function(uiSourceCode, lineNumber)
  4889. {
  4890. this._showSourceLine(uiSourceCode, lineNumber);
  4891. },
  4892.  
  4893.  
  4894. _showSourceLine: function(uiSourceCode, lineNumber)
  4895. {
  4896. var sourceFrame = this._showFile(uiSourceCode);
  4897. if (typeof lineNumber === "number")
  4898. sourceFrame.highlightLine(lineNumber);
  4899. sourceFrame.focus();
  4900.  
  4901. WebInspector.notifications.dispatchEventToListeners(WebInspector.UserMetrics.UserAction, {
  4902. action: WebInspector.UserMetrics.UserActionNames.OpenSourceLink,
  4903. url: uiSourceCode.url,
  4904. lineNumber: lineNumber
  4905. });
  4906. },
  4907.  
  4908.  
  4909. _showFile: function(uiSourceCode)
  4910. {
  4911. var sourceFrame = this._getOrCreateSourceFrame(uiSourceCode);
  4912. if (this._currentUISourceCode === uiSourceCode)
  4913. return sourceFrame;
  4914. this._currentUISourceCode = uiSourceCode;
  4915.  
  4916. if (this._navigator.isScriptSourceAdded(uiSourceCode))
  4917. this._navigator.revealUISourceCode(uiSourceCode);
  4918. this._editorContainer.showFile(uiSourceCode);
  4919. this._updateScriptViewStatusBarItems();
  4920.  
  4921. return sourceFrame;
  4922. },
  4923.  
  4924.  
  4925. _createSourceFrame: function(uiSourceCode)
  4926. {
  4927. var sourceFrame;
  4928. switch (uiSourceCode.contentType()) {
  4929. case WebInspector.resourceTypes.Script:
  4930. if (uiSourceCode.isSnippet && !uiSourceCode.isTemporary)
  4931. sourceFrame = new WebInspector.SnippetJavaScriptSourceFrame(this, uiSourceCode);
  4932. else
  4933. sourceFrame = new WebInspector.JavaScriptSourceFrame(this, uiSourceCode);
  4934. break;
  4935. case WebInspector.resourceTypes.Document:
  4936. sourceFrame = new WebInspector.JavaScriptSourceFrame(this, uiSourceCode);
  4937. break;
  4938. case WebInspector.resourceTypes.Stylesheet:
  4939. default:
  4940. sourceFrame = new WebInspector.UISourceCodeFrame(uiSourceCode);
  4941. break;
  4942. }
  4943. this._sourceFramesByUISourceCode.put(uiSourceCode, sourceFrame);
  4944. return sourceFrame;
  4945. },
  4946.  
  4947.  
  4948. _getOrCreateSourceFrame: function(uiSourceCode)
  4949. {
  4950. return this._sourceFramesByUISourceCode.get(uiSourceCode) || this._createSourceFrame(uiSourceCode);
  4951. },
  4952.  
  4953.  
  4954. viewForFile: function(uiSourceCode)
  4955. {
  4956. return this._getOrCreateSourceFrame(uiSourceCode);
  4957. },
  4958.  
  4959.  
  4960. _removeSourceFrame: function(uiSourceCode)
  4961. {
  4962. var sourceFrame = this._sourceFramesByUISourceCode.get(uiSourceCode);
  4963. if (!sourceFrame)
  4964. return;
  4965. this._sourceFramesByUISourceCode.remove(uiSourceCode);
  4966. sourceFrame.detach();
  4967. },
  4968.  
  4969. _clearCurrentExecutionLine: function()
  4970. {
  4971. if (this._executionSourceFrame)
  4972. this._executionSourceFrame.clearExecutionLine();
  4973. delete this._executionSourceFrame;
  4974. },
  4975.  
  4976. _executionLineChanged: function(event)
  4977. {
  4978. var uiLocation = event.data;
  4979.  
  4980. this._clearCurrentExecutionLine();
  4981. if (!uiLocation)
  4982. return;
  4983. var sourceFrame = this._getOrCreateSourceFrame(uiLocation.uiSourceCode);
  4984. sourceFrame.setExecutionLine(uiLocation.lineNumber);
  4985. this._executionSourceFrame = sourceFrame;
  4986. },
  4987.  
  4988. _revealExecutionLine: function(uiLocation)
  4989. {
  4990. var uiSourceCode = uiLocation.uiSourceCode;
  4991.  
  4992. if (uiSourceCode.isTemporary) {
  4993. if (this._currentUISourceCode && this._currentUISourceCode.scriptFile() && this._currentUISourceCode.scriptFile().isDivergingFromVM())
  4994. return;
  4995. this._editorContainer.addUISourceCode(uiSourceCode);
  4996. if (uiSourceCode.formatted() !== this._toggleFormatSourceButton.toggled)
  4997. uiSourceCode.setFormatted(this._toggleFormatSourceButton.toggled);
  4998. }
  4999. var sourceFrame = this._showFile(uiSourceCode);
  5000. sourceFrame.revealLine(uiLocation.lineNumber);
  5001. sourceFrame.focus();
  5002. },
  5003.  
  5004. _callFrameSelected: function(event)
  5005. {
  5006. var callFrame = event.data;
  5007.  
  5008. if (!callFrame)
  5009. return;
  5010.  
  5011. this.sidebarPanes.scopechain.update(callFrame);
  5012. this.sidebarPanes.watchExpressions.refreshExpressions();
  5013. this.sidebarPanes.callstack.setSelectedCallFrame(callFrame);
  5014. callFrame.createLiveLocation(this._revealExecutionLine.bind(this));
  5015. },
  5016.  
  5017. _editorClosed: function(event)
  5018. {
  5019. this._navigatorController.hideNavigatorOverlay();
  5020. var uiSourceCode =   (event.data);
  5021.  
  5022. if (this._currentUISourceCode === uiSourceCode)
  5023. delete this._currentUISourceCode;
  5024.  
  5025.  
  5026. this._updateScriptViewStatusBarItems();
  5027. WebInspector.searchController.resetSearch();
  5028. },
  5029.  
  5030. _editorSelected: function(event)
  5031. {
  5032. var uiSourceCode =   (event.data);
  5033. var sourceFrame = this._showFile(uiSourceCode);
  5034. this._navigatorController.hideNavigatorOverlay();
  5035. sourceFrame.focus();
  5036. WebInspector.searchController.resetSearch();
  5037. },
  5038.  
  5039. _scriptSelected: function(event)
  5040. {
  5041. var uiSourceCode =   (event.data.uiSourceCode);
  5042. var sourceFrame = this._showFile(uiSourceCode);
  5043. this._navigatorController.hideNavigatorOverlay();
  5044. if (sourceFrame && event.data.focusSource)
  5045. sourceFrame.focus();
  5046. },
  5047.  
  5048. _pauseOnExceptionStateChanged: function()
  5049. {
  5050. var pauseOnExceptionsState = WebInspector.settings.pauseOnExceptionStateString.get();
  5051. switch (pauseOnExceptionsState) {
  5052. case WebInspector.DebuggerModel.PauseOnExceptionsState.DontPauseOnExceptions:
  5053. this._pauseOnExceptionButton.title = WebInspector.UIString("Don't pause on exceptions.\nClick to Pause on all exceptions.");
  5054. break;
  5055. case WebInspector.DebuggerModel.PauseOnExceptionsState.PauseOnAllExceptions:
  5056. this._pauseOnExceptionButton.title = WebInspector.UIString("Pause on all exceptions.\nClick to Pause on uncaught exceptions.");
  5057. break;
  5058. case WebInspector.DebuggerModel.PauseOnExceptionsState.PauseOnUncaughtExceptions:
  5059. this._pauseOnExceptionButton.title = WebInspector.UIString("Pause on uncaught exceptions.\nClick to Not pause on exceptions.");
  5060. break;
  5061. }
  5062. this._pauseOnExceptionButton.state = pauseOnExceptionsState;
  5063. },
  5064.  
  5065. _updateDebuggerButtons: function()
  5066. {
  5067. if (WebInspector.debuggerModel.debuggerEnabled()) {
  5068. this.enableToggleButton.title = WebInspector.UIString("Debugging enabled. Click to disable.");
  5069. this.enableToggleButton.toggled = true;
  5070. this._pauseOnExceptionButton.visible = true;
  5071. this.panelEnablerView.detach();
  5072. } else {
  5073. this.enableToggleButton.title = WebInspector.UIString("Debugging disabled. Click to enable.");
  5074. this.enableToggleButton.toggled = false;
  5075. this._pauseOnExceptionButton.visible = false;
  5076. this.panelEnablerView.show(this.element);
  5077. }
  5078.  
  5079. if (this._paused) {
  5080. this._updateButtonTitle(this.pauseButton, WebInspector.UIString("Resume script execution (%s)."))
  5081. this.pauseButton.addStyleClass("paused");
  5082.  
  5083. this.pauseButton.disabled = false;
  5084. this.stepOverButton.disabled = false;
  5085. this.stepIntoButton.disabled = false;
  5086. this.stepOutButton.disabled = false;
  5087.  
  5088. this.debuggerStatusElement.textContent = WebInspector.UIString("Paused");
  5089. } else {
  5090. this._updateButtonTitle(this.pauseButton, WebInspector.UIString("Pause script execution (%s)."))
  5091. this.pauseButton.removeStyleClass("paused");
  5092.  
  5093. this.pauseButton.disabled = this._waitingToPause;
  5094. this.stepOverButton.disabled = true;
  5095. this.stepIntoButton.disabled = true;
  5096. this.stepOutButton.disabled = true;
  5097.  
  5098. if (this._waitingToPause)
  5099. this.debuggerStatusElement.textContent = WebInspector.UIString("Pausing");
  5100. else if (this._stepping)
  5101. this.debuggerStatusElement.textContent = WebInspector.UIString("Stepping");
  5102. else
  5103. this.debuggerStatusElement.textContent = "";
  5104. }
  5105. },
  5106.  
  5107. _clearInterface: function()
  5108. {
  5109. this.sidebarPanes.callstack.update(null);
  5110. this.sidebarPanes.scopechain.update(null);
  5111. this.sidebarPanes.jsBreakpoints.clearBreakpointHighlight();
  5112. this.sidebarPanes.domBreakpoints.clearBreakpointHighlight();
  5113. this.sidebarPanes.eventListenerBreakpoints.clearBreakpointHighlight();
  5114. this.sidebarPanes.xhrBreakpoints.clearBreakpointHighlight();
  5115.  
  5116. this._clearCurrentExecutionLine();
  5117. this._updateDebuggerButtons();
  5118. },
  5119.  
  5120. _enableDebugging: function()
  5121. {
  5122. this._toggleDebugging(this.panelEnablerView.alwaysEnabled);
  5123. },
  5124.  
  5125. _toggleDebugging: function(optionalAlways)
  5126. {
  5127. this._paused = false;
  5128. this._waitingToPause = false;
  5129. this._stepping = false;
  5130.  
  5131. if (WebInspector.debuggerModel.debuggerEnabled()) {
  5132. WebInspector.settings.debuggerEnabled.set(false);
  5133. WebInspector.debuggerModel.disableDebugger();
  5134. } else {
  5135. WebInspector.settings.debuggerEnabled.set(!!optionalAlways);
  5136. WebInspector.debuggerModel.enableDebugger();
  5137. }
  5138. },
  5139.  
  5140. _togglePauseOnExceptions: function()
  5141. {
  5142. var nextStateMap = {};
  5143. var stateEnum = WebInspector.DebuggerModel.PauseOnExceptionsState;
  5144. nextStateMap[stateEnum.DontPauseOnExceptions] = stateEnum.PauseOnAllExceptions;
  5145. nextStateMap[stateEnum.PauseOnAllExceptions] = stateEnum.PauseOnUncaughtExceptions;
  5146. nextStateMap[stateEnum.PauseOnUncaughtExceptions] = stateEnum.DontPauseOnExceptions;
  5147. WebInspector.settings.pauseOnExceptionStateString.set(nextStateMap[this._pauseOnExceptionButton.state]);
  5148. },
  5149.  
  5150. _togglePause: function()
  5151. {
  5152. if (this._paused) {
  5153. this._paused = false;
  5154. this._waitingToPause = false;
  5155. DebuggerAgent.resume();
  5156. } else {
  5157. this._stepping = false;
  5158. this._waitingToPause = true;
  5159. DebuggerAgent.pause();
  5160. }
  5161.  
  5162. this._clearInterface();
  5163. },
  5164.  
  5165. _stepOverClicked: function()
  5166. {
  5167. if (!this._paused)
  5168. return;
  5169.  
  5170. this._paused = false;
  5171. this._stepping = true;
  5172.  
  5173. this._clearInterface();
  5174.  
  5175. DebuggerAgent.stepOver();
  5176. },
  5177.  
  5178. _stepIntoClicked: function()
  5179. {
  5180. if (!this._paused)
  5181. return;
  5182.  
  5183. this._paused = false;
  5184. this._stepping = true;
  5185.  
  5186. this._clearInterface();
  5187.  
  5188. DebuggerAgent.stepInto();
  5189. },
  5190.  
  5191. _stepOutClicked: function()
  5192. {
  5193. if (!this._paused)
  5194. return;
  5195.  
  5196. this._paused = false;
  5197. this._stepping = true;
  5198.  
  5199. this._clearInterface();
  5200.  
  5201. DebuggerAgent.stepOut();
  5202. },
  5203.  
  5204. _toggleBreakpointsClicked: function(event)
  5205. {
  5206. WebInspector.debuggerModel.setBreakpointsActive(!WebInspector.debuggerModel.breakpointsActive());
  5207. },
  5208.  
  5209. _breakpointsActiveStateChanged: function(event)
  5210. {
  5211. var active = event.data;
  5212. this._toggleBreakpointsButton.toggled = active;
  5213. if (active) {
  5214. this._toggleBreakpointsButton.title = WebInspector.UIString("Deactivate breakpoints.");
  5215. WebInspector.inspectorView.element.removeStyleClass("breakpoints-deactivated");
  5216. this.sidebarPanes.jsBreakpoints.listElement.removeStyleClass("breakpoints-list-deactivated");
  5217. } else {
  5218. this._toggleBreakpointsButton.title = WebInspector.UIString("Activate breakpoints.");
  5219. WebInspector.inspectorView.element.addStyleClass("breakpoints-deactivated");
  5220. this.sidebarPanes.jsBreakpoints.listElement.addStyleClass("breakpoints-list-deactivated");
  5221. }
  5222. },
  5223.  
  5224. _evaluateSelectionInConsole: function()
  5225. {
  5226. var selection = window.getSelection();
  5227. if (selection.type === "Range" && !selection.isCollapsed)
  5228. WebInspector.evaluateInConsole(selection.toString());
  5229. },
  5230.  
  5231. _createDebugToolbar: function()
  5232. {
  5233. var debugToolbar = document.createElement("div");
  5234. debugToolbar.className = "status-bar";
  5235. debugToolbar.id = "scripts-debug-toolbar";
  5236.  
  5237. var title, handler;
  5238. var platformSpecificModifier = WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta;
  5239.  
  5240.  
  5241. handler = this._togglePause.bind(this);
  5242. this.pauseButton = this._createButtonAndRegisterShortcuts("scripts-pause", "", handler, WebInspector.ScriptsPanelDescriptor.ShortcutKeys.PauseContinue);
  5243. debugToolbar.appendChild(this.pauseButton);
  5244.  
  5245.  
  5246. title = WebInspector.UIString("Step over next function call (%s).");
  5247. handler = this._stepOverClicked.bind(this);
  5248. this.stepOverButton = this._createButtonAndRegisterShortcuts("scripts-step-over", title, handler, WebInspector.ScriptsPanelDescriptor.ShortcutKeys.StepOver);
  5249. debugToolbar.appendChild(this.stepOverButton);
  5250.  
  5251.  
  5252. title = WebInspector.UIString("Step into next function call (%s).");
  5253. handler = this._stepIntoClicked.bind(this);
  5254. this.stepIntoButton = this._createButtonAndRegisterShortcuts("scripts-step-into", title, handler, WebInspector.ScriptsPanelDescriptor.ShortcutKeys.StepInto);
  5255. debugToolbar.appendChild(this.stepIntoButton);
  5256.  
  5257.  
  5258. title = WebInspector.UIString("Step out of current function (%s).");
  5259. handler = this._stepOutClicked.bind(this);
  5260. this.stepOutButton = this._createButtonAndRegisterShortcuts("scripts-step-out", title, handler, WebInspector.ScriptsPanelDescriptor.ShortcutKeys.StepOut);
  5261. debugToolbar.appendChild(this.stepOutButton);
  5262.  
  5263. this._toggleBreakpointsButton = new WebInspector.StatusBarButton(WebInspector.UIString("Deactivate breakpoints."), "toggle-breakpoints");
  5264. this._toggleBreakpointsButton.toggled = true;
  5265. this._toggleBreakpointsButton.addEventListener("click", this._toggleBreakpointsClicked, this);
  5266. debugToolbar.appendChild(this._toggleBreakpointsButton.element);
  5267.  
  5268. this.debuggerStatusElement = document.createElement("div");
  5269. this.debuggerStatusElement.id = "scripts-debugger-status";
  5270. debugToolbar.appendChild(this.debuggerStatusElement);
  5271.  
  5272. return debugToolbar;
  5273. },
  5274.  
  5275. _updateButtonTitle: function(button, buttonTitle)
  5276. {
  5277. button.buttonTitle = buttonTitle;
  5278. var hasShortcuts = button.shortcuts && button.shortcuts.length;
  5279. if (hasShortcuts)
  5280. button.title = String.vsprintf(buttonTitle, [button.shortcuts[0].name]);
  5281. else
  5282. button.title = buttonTitle;
  5283. },
  5284.  
  5285.  
  5286. _createButtonAndRegisterShortcuts: function(buttonId, buttonTitle, handler, shortcuts)
  5287. {
  5288. var button = document.createElement("button");
  5289. button.className = "status-bar-item";
  5290. button.id = buttonId;
  5291. button.shortcuts = shortcuts;
  5292. this._updateButtonTitle(button, buttonTitle);
  5293. button.disabled = true;
  5294. button.appendChild(document.createElement("img"));
  5295. button.addEventListener("click", handler, false);
  5296.  
  5297. this.registerShortcuts(shortcuts, handler);
  5298.  
  5299. return button;
  5300. },
  5301.  
  5302. searchCanceled: function()
  5303. {
  5304. if (this._searchView)
  5305. this._searchView.searchCanceled();
  5306.  
  5307. delete this._searchView;
  5308. delete this._searchQuery;
  5309. },
  5310.  
  5311.  
  5312. performSearch: function(query)
  5313. {
  5314. WebInspector.searchController.updateSearchMatchesCount(0, this);
  5315.  
  5316. if (!this.visibleView)
  5317. return;
  5318.  
  5319.  
  5320. this.searchCanceled();
  5321.  
  5322. this._searchView = this.visibleView;
  5323. this._searchQuery = query;
  5324.  
  5325. function finishedCallback(view, searchMatches)
  5326. {
  5327. if (!searchMatches)
  5328. return;
  5329.  
  5330. WebInspector.searchController.updateSearchMatchesCount(searchMatches, this);
  5331. view.jumpToNextSearchResult();
  5332. WebInspector.searchController.updateCurrentMatchIndex(view.currentSearchResultIndex, this);
  5333. }
  5334.  
  5335. this._searchView.performSearch(query, finishedCallback.bind(this));
  5336. },
  5337.  
  5338. jumpToNextSearchResult: function()
  5339. {
  5340. if (!this._searchView)
  5341. return;
  5342.  
  5343. if (this._searchView !== this.visibleView) {
  5344. this.performSearch(this._searchQuery);
  5345. return;
  5346. }
  5347.  
  5348. if (this._searchView.showingLastSearchResult())
  5349. this._searchView.jumpToFirstSearchResult();
  5350. else
  5351. this._searchView.jumpToNextSearchResult();
  5352. WebInspector.searchController.updateCurrentMatchIndex(this._searchView.currentSearchResultIndex, this);
  5353. return true;
  5354. },
  5355.  
  5356. jumpToPreviousSearchResult: function()
  5357. {
  5358. if (!this._searchView)
  5359. return false;
  5360.  
  5361. if (this._searchView !== this.visibleView) {
  5362. this.performSearch(this._searchQuery);
  5363. if (this._searchView)
  5364. this._searchView.jumpToLastSearchResult();
  5365. return;
  5366. }
  5367.  
  5368. if (this._searchView.showingFirstSearchResult())
  5369. this._searchView.jumpToLastSearchResult();
  5370. else
  5371. this._searchView.jumpToPreviousSearchResult();
  5372. WebInspector.searchController.updateCurrentMatchIndex(this._searchView.currentSearchResultIndex, this);
  5373. },
  5374.  
  5375.  
  5376. canSearchAndReplace: function()
  5377. {
  5378. var view =   (this.visibleView);
  5379. return !!view && view.canEditSource();
  5380. },
  5381.  
  5382.  
  5383. replaceSelectionWith: function(text)
  5384. {
  5385. var view =   (this.visibleView);
  5386. view.replaceSearchMatchWith(text);
  5387. },
  5388.  
  5389.  
  5390. replaceAllWith: function(query, text)
  5391. {
  5392. var view =   (this.visibleView);
  5393. view.replaceAllWith(query, text);
  5394. },
  5395.  
  5396. _toggleFormatSource: function()
  5397. {
  5398. this._toggleFormatSourceButton.toggled = !this._toggleFormatSourceButton.toggled;
  5399. var uiSourceCodes = this._workspace.uiSourceCodes();
  5400. for (var i = 0; i < uiSourceCodes.length; ++i)
  5401. uiSourceCodes[i].setFormatted(this._toggleFormatSourceButton.toggled);
  5402.  
  5403. WebInspector.notifications.dispatchEventToListeners(WebInspector.UserMetrics.UserAction, {
  5404. action: WebInspector.UserMetrics.UserActionNames.TogglePrettyPrint,
  5405. enabled: this._toggleFormatSourceButton.toggled,
  5406. url: this._editorContainer.currentFile().url
  5407. });
  5408. },
  5409.  
  5410. addToWatch: function(expression)
  5411. {
  5412. this.sidebarPanes.watchExpressions.addExpression(expression);
  5413. },
  5414.  
  5415. _toggleBreakpoint: function()
  5416. {
  5417. var sourceFrame = this.visibleView;
  5418. if (!sourceFrame)
  5419. return;
  5420.  
  5421. if (sourceFrame instanceof WebInspector.JavaScriptSourceFrame) {
  5422. var javaScriptSourceFrame =   (sourceFrame);
  5423. javaScriptSourceFrame.toggleBreakpointOnCurrentLine();
  5424. }            
  5425. },
  5426.  
  5427. _showOutlineDialog: function()
  5428. {
  5429. var uiSourceCode = this._editorContainer.currentFile();
  5430. if (!uiSourceCode)
  5431. return;
  5432.  
  5433. switch (uiSourceCode.contentType()) {
  5434. case WebInspector.resourceTypes.Document:
  5435. case WebInspector.resourceTypes.Script:
  5436. WebInspector.JavaScriptOutlineDialog.show(this.visibleView, uiSourceCode);
  5437. break;
  5438. case WebInspector.resourceTypes.Stylesheet:
  5439. WebInspector.StyleSheetOutlineDialog.show(this.visibleView, uiSourceCode);
  5440. break;
  5441. }
  5442. },
  5443.  
  5444. _installDebuggerSidebarController: function()
  5445. {
  5446. this._toggleDebuggerSidebarButton = new WebInspector.StatusBarButton(WebInspector.UIString("Hide debugger"), "scripts-debugger-show-hide-button", 3);
  5447. this._toggleDebuggerSidebarButton.state = "shown";
  5448. this._toggleDebuggerSidebarButton.addEventListener("click", clickHandler, this);
  5449.  
  5450. function clickHandler()
  5451. {
  5452. if (this._toggleDebuggerSidebarButton.state === "shown")
  5453. this._hideDebuggerSidebar();
  5454. else
  5455. this._showDebuggerSidebar();
  5456. }
  5457. this.editorView.element.appendChild(this._toggleDebuggerSidebarButton.element);
  5458.  
  5459. if (WebInspector.settings.debuggerSidebarHidden.get())
  5460. this._hideDebuggerSidebar();
  5461.  
  5462. },
  5463.  
  5464. _showDebuggerSidebar: function()
  5465. {
  5466. if (this._toggleDebuggerSidebarButton.state === "shown")
  5467. return;
  5468. this._toggleDebuggerSidebarButton.state = "shown";
  5469. this._toggleDebuggerSidebarButton.title = WebInspector.UIString("Hide debugger");
  5470. this.splitView.showSidebarElement();
  5471. this.debugSidebarResizeWidgetElement.removeStyleClass("hidden");
  5472. WebInspector.settings.debuggerSidebarHidden.set(false);
  5473. },
  5474.  
  5475. _hideDebuggerSidebar: function()
  5476. {
  5477. if (this._toggleDebuggerSidebarButton.state === "hidden")
  5478. return;
  5479. this._toggleDebuggerSidebarButton.state = "hidden";
  5480. this._toggleDebuggerSidebarButton.title = WebInspector.UIString("Show debugger");
  5481. this.splitView.hideSidebarElement();
  5482. this.debugSidebarResizeWidgetElement.addStyleClass("hidden");
  5483. WebInspector.settings.debuggerSidebarHidden.set(true);
  5484. },
  5485.  
  5486. _fileRenamed: function(event)
  5487. {
  5488. var uiSourceCode =   (event.data.uiSourceCode);
  5489. var name =   (event.data.name);
  5490. if (!uiSourceCode.isSnippet)
  5491. return;
  5492. WebInspector.scriptSnippetModel.renameScriptSnippet(uiSourceCode, name);
  5493. },
  5494.  
  5495.  
  5496. _snippetCreationRequested: function(event)
  5497. {
  5498. var uiSourceCode = WebInspector.scriptSnippetModel.createScriptSnippet();
  5499. this._showSourceLine(uiSourceCode);
  5500.  
  5501. var shouldHideNavigator = !this._navigatorController.isNavigatorPinned();
  5502. if (this._navigatorController.isNavigatorHidden())
  5503. this._navigatorController.showNavigatorOverlay();
  5504. this._navigator.rename(uiSourceCode, callback.bind(this));
  5505.  
  5506.  
  5507. function callback(committed)
  5508. {
  5509. if (shouldHideNavigator)
  5510. this._navigatorController.hideNavigatorOverlay();
  5511.  
  5512. if (!committed) {
  5513. WebInspector.scriptSnippetModel.deleteScriptSnippet(uiSourceCode);
  5514. return;
  5515. }
  5516.  
  5517. this._showSourceLine(uiSourceCode);
  5518. }
  5519. },
  5520.  
  5521.  
  5522. _itemRenamingRequested: function(event)
  5523. {
  5524. var uiSourceCode =   (event.data);
  5525.  
  5526. var shouldHideNavigator = !this._navigatorController.isNavigatorPinned();
  5527. if (this._navigatorController.isNavigatorHidden())
  5528. this._navigatorController.showNavigatorOverlay();
  5529. this._navigator.rename(uiSourceCode, callback.bind(this));
  5530.  
  5531.  
  5532. function callback(committed)
  5533. {
  5534. if (shouldHideNavigator && committed) {
  5535. this._navigatorController.hideNavigatorOverlay();
  5536. this._showSourceLine(uiSourceCode);
  5537. }
  5538. }
  5539. },
  5540.  
  5541.  
  5542. _showLocalHistory: function(uiSourceCode)
  5543. {
  5544. WebInspector.RevisionHistoryView.showHistory(uiSourceCode);
  5545. },
  5546.  
  5547.  
  5548. appendApplicableItems: function(event, contextMenu, target)
  5549. {
  5550. this._appendUISourceCodeItems(contextMenu, target);
  5551. this._appendFunctionItems(contextMenu, target);
  5552. },
  5553.  
  5554.  
  5555. _appendUISourceCodeItems: function(contextMenu, target)
  5556. {
  5557. if (!(target instanceof WebInspector.UISourceCode))
  5558. return;
  5559.  
  5560. var uiSourceCode =   (target);
  5561. contextMenu.appendItem(WebInspector.UIString("Local modifications..."), this._showLocalHistory.bind(this, uiSourceCode));
  5562. var resource = WebInspector.resourceForURL(uiSourceCode.url);
  5563. if (resource && resource.request)
  5564. contextMenu.appendApplicableItems(resource.request);
  5565. },
  5566.  
  5567.  
  5568. _appendFunctionItems: function(contextMenu, target)
  5569. {
  5570. if (!(target instanceof WebInspector.RemoteObject))
  5571. return;
  5572. var remoteObject =   (target);
  5573. if (remoteObject.type !== "function")
  5574. return;
  5575.  
  5576. function didGetDetails(error, response)
  5577. {
  5578. if (error) {
  5579. console.error(error);
  5580. return;
  5581. }
  5582. WebInspector.inspectorView.showPanelForAnchorNavigation(this);
  5583. var uiLocation = WebInspector.debuggerModel.rawLocationToUILocation(response.location);
  5584. this._showSourceLine(uiLocation.uiSourceCode, uiLocation.lineNumber);
  5585. }
  5586.  
  5587. function revealFunction()
  5588. {
  5589. DebuggerAgent.getFunctionDetails(remoteObject.objectId, didGetDetails.bind(this));
  5590. }
  5591.  
  5592. contextMenu.appendItem(WebInspector.UIString("Show function definition"), revealFunction.bind(this));
  5593. },
  5594.  
  5595. showGoToSourceDialog: function()
  5596. {
  5597. WebInspector.OpenResourceDialog.show(this, this._workspace, this.editorView.mainElement);
  5598. },
  5599.  
  5600. __proto__: WebInspector.Panel.prototype
  5601. }
  5602.